Как отправить данные django formset на сервер с помощью ajax?
Я пытаюсь отправить данные на сервер после отправки формы, но мой скрипт не работает. У меня есть несколько форм. Одна из них используется из django-formset.
Формы:
class UploadReceiptForm(forms.ModelForm):
class Meta:
model = Receipt
fields = ('payment_type', 'payment_mandatory_code', 'payment_optional_code',
'payment_date', 'payment_amount', 'image', 'description')
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['payment_type'].required = True
self.fields['payment_mandatory_code'].required = True
self.fields['payment_date'].required = True
self.fields['payment_date'].input_formats += ['%Y/%m/%d']
self.fields['payment_amount'].required = True
self.fields['image'].required = True
def save(self, rrr):
receipt: Receipt = super().save(commit=False)
receipt.review_request = rrr
receipt.save()
return receipt
def clean(self):
cleaned_data = self.cleaned_data
payment_type = cleaned_data['payment_type']
if payment_type == Receipt.PaymentTypes.LETTER_OF_ATTORNEY.value:
cleaned_data['payment_amount'] = 0
return cleaned_data
def clean_payment_date(self):
j_date = self.cleaned_data['payment_date']
try:
j_year, j_month, j_day = [int(x) for x in str(j_date).split('-')]
except ValueError:
raise ValidationError("تاریخ به فرمت صحیحی وارد نشده است")
try:
date = jdatetime.date(j_year, j_month, j_day).togregorian()
except Exception as ex:
raise ValidationError("تاریخ به فرمت صحیحی وارد نشده است")
return date
def clean_description(self):
desc = self.cleaned_data['description']
if desc and len(desc) > 300:
raise ValidationError("توضیحات باید کمتر از 300 حرف باشد")
return desc
UploadReceiptFormSet = formset_factory(UploadReceiptForm, extra=0, can_order=False, can_delete=False, max_num=20,validate_max=20, absolute_max=20, can_delete_extra=False)
Базовый вид класса:
Файл шаблона:
После попытки отправить форму у меня в консоли появляется ошибка: Uncaught ReferenceError: SubmitButtonClicked is not defined
.