I've a modelform and I excluded two fields, the create_date
and the created_by
fields. Now I get the "Not Null" error when using the save()
method because the created_by
is empty.
I've tried to add the user id to the form before the save()
method like this: form.cleaned_data['created_by'] = 1
and form.cleaned_data['created_by_id'] = 1
. But none of this works.
Can someone explain to me how I can 'add' additional stuff to the submitted modelform so that it will save?
class Location(models.Model):
name = models.CharField(max_length = 100)
created_by = models.ForeignKey(User)
create_date = models.DateTimeField(auto_now=True)
class LocationForm(forms.ModelForm):
class Meta:
model = Location
exclude = ('created_by', 'create_date', )