#12392: Create_object generic view does not provide a way to pre-populate a form -------------------------------------------------+-------------------------- Reporter: stewart.mathe...@gmail.com | Owner: nobody Status: closed | Milestone: Component: Generic views | Version: SVN Resolution: wontfix | Keywords: pre-populate, generic, view, dictionary Stage: Unreviewed | Has_patch: 0 Needs_docs: 0 | Needs_tests: 0 Needs_better_patch: 0 | -------------------------------------------------+-------------------------- Changes (by lukeplant):
* status: new => closed * resolution: => wontfix Comment: Pass in your own form class which implements `__init__` to provide the 'initial' keyword argument: {{{ #!python from django.forms import ModelForm from myapp.models import MyModel class MyModelForm(ModelForm): class Meta: model = MyModel def __init__(self, *args, **kwargs): kwargs['initial'] = {'field1':'val1'} return super(MyModelForm, self).__init__(*args, **kwargs) }}} Then pass `MyModelForm` as the `form_class` argument. I didn't try this, but I'm fairly sure the basic approach should work. Since it is fairly simple and avoids cluttering the generic view interface, I'm closing WONTFIX. -- Ticket URL: <http://code.djangoproject.com/ticket/12392#comment:4> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.