On Sun, May 15, 2011 at 10:24 AM, Shawn Milochik <sh...@milochik.com> wrote: > I think the reason you're getting the error you are is that you didn't add > 'company' to 'exclude' in your modelform. > > The code you pasted indicates that you will have an existing object 100% of > the time in this view. If that's the case, your line to instantiate the form > with request.POST and the instance kwarg should take care of remembering its > existing 'company' value. > > If you want one form that is used for both creating a new Contact and > editing an existing contact then there are ways to do that too. > > Here's one: > > In the __init__ of your form, check whether self.instance.id exists. If so, > you can del(self.fields['company']). It won't be available in the form. > Then, if you pass 'instance' when you create the form in your view your > modelform will know what the proper value is.
I'm expected to exclude fields so my edit form works when data already exists in the database? Great, but now I find that change to get my edit form working has broken my add form because the company no longer exists when I post the form, even though it's right there in the post data. This is so overly complicated. What is the point of having a model form if you're just going to exclude important things from it to cheat to get by an edit form? -- Greg Donald destiney.com | gregdonald.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.