Hello, I am trying to submitting my modelform and want to save as model in admin panel bu submit button just refreshes the page and nothing happens. i can save models from admin pannel manually but cannot this way. thank you
views.py:
def toplantıEkle(request):
if request.method == "POST":
form = ToplantıOluşturmaForm(data=request.GET, files=request.FILES)
if form.is_valid():
yeni_toplantı = form.save(commit=False)
yeni_toplantı.user = request.user
yeni_toplantı.save()
else:
form = ToplantıOluşturmaForm(data=request.GET)
return render( request, "toplantıapp/toplantıekle.html",{
'form':form
})
models.py:
class ToplantıOluşturma(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
konu = models.CharField(max_length=100)
tarih = models.DateTimeField(auto_now_add=True)
katılımcı = models.CharField(max_length=50, blank=False)
tgs_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)
def __str__(self):
return self.konu
forms.py:
class ToplantıOluşturmaForm(forms.ModelForm):
class Meta:
model = ToplantıOluşturma
fields = '__all__'
widgets = {
'tarih':forms.DateInput(attrs={'type':'date'}),
'açıklama':forms.Textarea(attrs={'cols':50,'rows':35, 'placeholder':'Açıklama', 'style': 'width:100%; border: solid 1px gray'}),
}
labels = {
'konu':'formkonu',
'tarih':'tarih',
'katılımcı':'katılımcı',
'açıklama':'açıklama'
}
and this is my template:
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div class="card">
<div class="container">
<div class="row justify-content-between">
<div class="col-5">
<input id="formkonu" class="konu" type="text" name="formkonu" value="{{formkonu}}" placeholder="Konu">
</br>
<input type="datetime" class="tarih" id="datepicker" placeholder="Tarih " value="{{tarih}}">
</br></br>
<div class="input-group" style="padding-right: 16%;">
<div id="çalışan" class="form-control select multiple" data-list="çalışanlar" style="width: 70%; border-radius: 0%; border: 1px solid gray; height: 45px;">
<input id="çalışan_girişi" type="text" data-bs-toggle="dropdown" placeholder="Çalışan" style="width: 50px;"/>
<div class="dropdown-menu"></div>
<select name="çalışan" multiple hidden>
<option></option> <!--Katılımcı input areanın büyümemesini çöz!!!-->
</select>
</div>
<label style="padding: 3%;">
<input class="mail1" type="checkbox" id="mail" name="mail"> Mail
</label>
</div>
<input id="tgs_dışı_katılımcı" class="tgs_dışı_katılımcı" type="text" name="tgs_dışı_katılımcı" value="{{ tgs_dışı_katılımcı }}" placeholder="TGS Dışı Katılımcılar">
<label style="margin-left: 8px;">
<input class="mail2" type="checkbox" id="mail" name="mail"> Mail
</label>
</br>
</br>
<input class="dosya_ekleme" id="dosya_ekleme" type="file" name="dosya_ekleme" value="{{dosya_ekleme}}" placeholder="Dosya Yükle" style="display:none;">
<label for="dosya_ekleme" class="dosya_ekleme" style="color: gray;">Dosya Yükle </label>
</div>
<div class="col-5">
{{form.açıklama}}
</div>
</div>
</div>
</div>
<input class="button" type="submit">
<button class="button1" type="submit">Kaydet</button>
</form>