Let’s say trying to use django.views.generic.create_update.create_object to allow the user to a blog entry instance. On the Entry model, there is a required field for the user, that I don’t want to show up as an editable field on the blog entry form. So, I would include it into the EntryForm.Meta.exclude tuple.
Where should I set the value for the user property on the resulting model instance? Would I have to stop using the create_object generic view and write my own?
I don’t think you can accomplish this with generic views, they don’t have much in the way of post-processing data. Thankfully, it isn’t hard to write your own view to do the same thing.
(Adapted from http://www.djangobook.com/en/1.0/chapter07/)
Of course you’ll have to use your own names and such, but that’s the logic. Basically you’re checking if a form has been submitted, and if so get the Entry, add in a username, and save it as usual. As far as differences from the generic create_object view are concerned, instead of specifying things such as the post_redirect_url in the view call, you give them directly. Check the docs of render_to_response and HttpResponseRedirect for more info.