По непонятной причине джанга не может создать новый id
class Data(models.Model):
field1 = models.CharField(max_length=45, blank=True, null=True)
field2 = models.CharField(max_length=45, blank=True, null=True)
field3 = models.IntegerField(blank=True, null=True)
field4 = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
field5 = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
field6 = models.IntegerField(blank=True, null=True)
field7 = models.DateField(blank=True, null=True)
field8 = models.CharField(max_length=255, blank=True, null=True)
form.py
class DataForm(forms.ModelForm):
class Meta:
model = Data
fields = '__all__'
views.py
data = Data.objects.all()
DataFormSet = modelformset_factory(Data, exclude=('field6',), form=DataForm)
if request.method == 'POST':
data_form = DataFormSet(request.POST, request.FILES)
if data_form.is_valid():
data_form.save()
else:
data_form = DataFormSet(queryset=data)
{{ formset_advance.management_form }}
{% for form_advance in formset_advance %}
{{ form_advance.idpub_royalties_advances }}
<tr class="ppradvtbl">
<td>{{ form_advance.advance_num }}</td>
<td>{{ form_advance.currency_amount }}</td>
<td>{{ form_advance.home_currency_amount }}</td>
<td><span class="datePicker">{{ form_advance.invoice_rec_date }}</span></td>
<td>{{ form_advance.pay_question }}</td>
<td>{{ form_advance.advance_note }}</td>
</tr>
{% endfor %}
ValidationError at /url
[u"'' value must be an integer."]
Traceback:
File "/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
22. return view_func(request, *args, **kwargs)
File "/dimo/Project/dimo/views.py" in royalties_rights
440. if royalties_advance.exists() and formset_advance.is_valid():
File "/lib/python2.7/site-packages/django/forms/formsets.py" in is_valid
304. self.errors
File "/lib/python2.7/site-packages/django/forms/formsets.py" in errors
278. self.full_clean()
File "/lib/python2.7/site-packages/django/forms/formsets.py" in full_clean
326. form = self.forms[i]
File "/lib/python2.7/site-packages/django/utils/functional.py" in __get__
59. res = instance.__dict__[self.name] = self.func(instance)
File "/lib/python2.7/site-packages/django/forms/formsets.py" in forms
142. forms = [self._construct_form(i) for i in range(self.total_form_count())]
File "/lib/python2.7/site-packages/django/forms/models.py" in _construct_form
586. pk = to_python(pk)
File "/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in to_python
969. params={'value': value},
Exception Type: ValidationError at /url
Exception Value: [u"'' value must be an integer."]