C
C
cusinoa2016-07-02 10:37:14
Django
cusinoa, 2016-07-02 10:37:14

How to get rid of the error that occurs when saving the formset?

Error occurs when saving formsets
ValidationError [u"'' value must be an integer."]
Below code:
models.py

class RoyaltiesAd(models.Model):
    isbn = models.CharField(max_length=45, blank=True, null=True)
    supplier_num = models.CharField(max_length=45, blank=True, null=True)
    advance_num = models.IntegerField(blank=True, null=True)
    home_currency_amount = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
    currency_amount = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
    pay_question = models.IntegerField(blank=True, null=True)
    invoice_rec_date = models.DateField(blank=True, null=True)
    advance_note = models.CharField(max_length=255, blank=True, null=True)

forms.py
class RoyaltiesAdForm(forms.ModelForm):
    class Meta:
        model = RoyaltiesAd
        fields = '__all__'

views.py
if request.method == 'POST':
    formset = RoyaltiesAdSet(request.POST)
    if formset.is_valid():
        formset.save()
else:
    formset = RoyaltiesAdSet()

return render(request, 'template.html', {'formset': formset,})

template.html
<form method="POST" action="" enctype="multipart/form-data">
      {% csrf_token %}
      {{ formset }}
    </form>

As I understand from the debug, Jang cannot create an id. Who faced such error? Or any ideas how to fix it? Thanks in advance

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question