#14167: Using Instances in Generic Create/Update/Delete
----------------------------------------+-----------------------------------
Reporter: monokrome | Owner: nobody
Status: new | Milestone:
Component: Generic views | Version: 1.2
Keywords: generic views DRY instance | Stage: Unreviewed
Has_patch: 0 |
----------------------------------------+-----------------------------------
I would like to proposal that django's create/update/delete methods be
able to receive an instance of a model instead of a class reference.
Albeit, it is not difficult to create your own create/update/delete method
- using django's generic views would allow an application to easily
inherit any additional functionality that might be added to these generic
views in the future. It also provides the added benefit of centralizing
the work happening to the models, and would help model code follow the DRY
principal in many cases.
Here is an example of how a generic view may be used with this idea in
mind. In my opinion, this is much more readable than working with the form
yourself:
{{{
# Assume that we have a model `Job` with a foreign key `user`
from models import Job
def create_job(request):
""" Create a new job. """
job_instance = Job()
job_instance.user = request.user
kwargs = {
'instance': job_instance,
'login_required': True,
'template_name': 'jobs/create.html',
}
return create_object(request, **kwargs)
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/14167>
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.