hello everyone
I am trying to submit a post to save the models but submitting does nothing. there is no errors or warnings, cmd shows “HTTP/1.1” 200 8553".
here is my code:
views.py;
def toplantıekle(request):
if request.method == 'POST':
form = ToplantıForm(data=request.POST, files=request.FILES)
if form.is_valid():
yeni_toplantı = form.save(commit=False)
yeni_toplantı.user = request.user
yeni_toplantı.save()
return redirect('http://127.0.0.1:8000/')
else:
form = ToplantıForm(data=request.GET)
return render(request, 'toplantıapp/toplantıekle.html', {
'form':form
})
forms.py;
class ToplantıForm(forms.ModelForm):
katılımcı = forms.MultipleChoiceField(choices = demo_seçimler, required=True)
class Meta:
model = Toplantı
fields = ('konu','tarih','katılımcı','dış_katılımcı','dosya_yükle','açıklama','profile')
widgets = {
'konu':forms.TextInput(attrs={"placeholder":"Toplantının Konusu","style":"width:70%; height:32px; border:1px solid #A0A0A0; border-radius:3px"}),
'açıklama':forms.Textarea(attrs={'cols':50,'rows':25, 'placeholder':'Açıklama','style':'width:100%; border:solid 1px #A0A0A0 ; margin-bottom:10px; border-radius:3px;'}),
'tarih':forms.DateTimeInput(attrs={"type":"text", "onfocus":"(this.type='datetime-local')","placeholder":"Tarih","id":"tarih"}),
'dış_katılımcı':forms.TextInput(attrs={"placeholder":"TGS Dışı Katılımcılar","style":"width:70%; height:32px; border:solid 1px #A0A0A0; border-radius:3px;"}),
'dosya_yükle':forms.FileInput(attrs={"placeholder":"Dosya Yükle","style":"display:none; border:1px solid #D8D8D8; padding-left:2p; padding-top:10px; padding-bottom:12px; padding-right;52.8%; background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Upload_alt_font_awesome.svg/1024px-Upload_alt_font_awesome.svg.png'); background-position:98%; background-repeat: no-repeat; background-size: 25px;","id":"dosya_ekleme","name":"dosya_ekleme","class":"dosya_ekleme"}),
'katılımcı':forms.CheckboxInput(attrs={"placeholder":"TGS Katılımcıları","class":"katılımcıselect"})
}
labels = {
'konu':'formkonu',
'tarih':'tarih',
'katılımcı':'katılımcı',
'açıklama':'açıklama',
}
models.py;
class Toplantı(models.Model):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE)
konu = models.CharField(max_length=100, blank=False)
tarih = models.DateTimeField()
katılımcı = models.CharField(max_length=50, blank=False)
dış_katılımcı = models.CharField(max_length=50, blank=True)
dosya_yükle = models.FileField(upload_to='uploads/', blank=True)
açıklama = models.TextField(blank=True, max_length=5255)
and my template;
{% load static %}
<head>
<link rel="stylesheet" href="{% static 'toplantıapp/toplantıekle.css' %}">
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous"/>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
</head>
<body>
<h4 class="başlık">YENİ KAYIT EKLE</h4>
<form method="POST" enctype="multipart/form-data" autocomplete="off">
{% csrf_token %}
<div class="card" style="border-radius: 3px; border: 1px solid #A0A0A0;">
<div class="container">
<div class="row justify-content-between">
<div class="col-5">
{{ form.konu }}
</br>
{{ form.tarih }}
</br></br>
{{ form.katılımcı }} <input class="mailcheck1" type="checkbox">
</br></br>
{{ form.dış_katılımcı }} <input class="mailcheck2" type="checkbox">
</br></br>
{{ form.dosya_yükle }}
<label for="dosya_ekleme" class="dosya_ekleme" style="color: gray;">Dosya Yükle </label>
</div>
<div class="col-6">
{{ form.açıklama }}
</div>
</div>
</div>
</div>
<a href="http://127.0.0.1:8000/"><input class="button" type="button" value="Vazgeç"></a>
<input class="button1" type="submit" value="Kaydet">
</form>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('#id_katılımcı').select2({
placeholder: "TGS Katılımcı",
allowClear: true,
width:'70%',
closeOnSelect: false,
});
});
</script>
</body>
thank you