I’m having trouble submitting a ModelForm.
Basically, one of my attributes is excluded, and I’m augmenting the request.POST object to include it (so the ORM can save it without any issues) when we create the form. From my understanding (again, I’m a n00b when it comes to django), that’s how it works.
I’m getting an IntegrityError when calling form.save().
The code I’m working with is here: http://dpaste.com/783425/.
EDIT: Code pasted below for posterity.
# forms.py
class CreateNewItemForm(ModelForm):
class Meta:
model = X.models.Y
exclude = ('person',)
# views.py
def myview(request, person_id):
if request.method == "POST":
data = request.POST.copy()
data['person'] = Person.objects.get(id=person_id)
# NOTE: I've also tried: data['person'] = person_id
form = CreateNewItemForm(data)
if form.is_valid():
form.save() # throws the IntegrityError
I think that this code is wrong… Change your code for this…