Ticket #14167: create_update.py.patch

File create_update.py.patch, 1.3 KB (added by monokrome, 14 years ago)

A patch that implements the "instance" keyword on the create_object generic view.

  • django/views/generic/create_update.py

    diff --git a/django/views/generic/create_update.py b/django/views/generic/create_update.py
    index 76575f9..c05137b 100644
    a b def lookup_object(model, object_id, slug, slug_field):  
    9191        raise Http404("No %s found for %s"
    9292                      % (model._meta.verbose_name, lookup_kwargs))
    9393
    94 def create_object(request, model=None, template_name=None,
     94def create_object(request, instance=None, model=None, template_name=None,
    9595        template_loader=loader, extra_context=None, post_save_redirect=None,
    9696        login_required=False, context_processors=None, form_class=None):
    9797    """
    def create_object(request, model=None, template_name=None,  
    106106    if login_required and not request.user.is_authenticated():
    107107        return redirect_to_login(request.path)
    108108
     109    if model is None and instance is not None:
     110        model = instance.__class__
     111
    109112    model, form_class = get_model_and_form_class(model, form_class)
    110113    if request.method == 'POST':
    111         form = form_class(request.POST, request.FILES)
     114        form = form_class(request.POST, request.FILES, instance=instance)
    112115        if form.is_valid():
    113116            new_object = form.save()
    114117           
Back to Top