Ticket #4667: 4667-added-custom-formset.diff

File 4667-added-custom-formset.diff, 3.9 KB (added by Honza Král, 17 years ago)

new two-part patch for django @6657 (first part)

  • django/contrib/admin/options.py

    commit ffe91e663f807ed138da33413d938ef3c98719c0
    Author: Honza Král <Honza.Kral@gmail.com>
    Date:   Sun Nov 11 21:24:18 2007 +0100
    
        Added Formset Overridability for #4667
        
        http://code.djangoproject.com/ticket/4667
    
    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index cafa054..d5f4c15 100644
    a b  
    11from django import oldforms, template
    22from django import newforms as forms
    33from django.newforms.formsets import all_valid
    4 from django.contrib.contenttypes.models import ContentType
    54from django.contrib.admin import widgets
    65from django.contrib.admin.util import get_deleted_objects
    76from django.core.exceptions import ImproperlyConfigured, PermissionDenied
    class ModelAdmin(BaseModelAdmin):  
    451450            return HttpResponseRedirect("../")
    452451
    453452    def render_change_form(self, model, context, add=False, change=False, form_url=''):
     453        from django.contrib.contenttypes.models import ContentType
    454454        opts = model._meta
    455455        app_label = opts.app_label
    456456        ordered_objects = opts.get_ordered_objects()
    class InlineModelAdmin(BaseModelAdmin):  
    721721    template = None
    722722    verbose_name = None
    723723    verbose_name_plural = None
     724    formset = None
    724725
    725726    def __init__(self, parent_model, admin_site):
    726727        self.admin_site = admin_site
    class InlineModelAdmin(BaseModelAdmin):  
    738739            fields = flatten_fieldsets(self.declared_fieldsets)
    739740        else:
    740741            fields = None
    741         return forms.inline_formset(self.parent_model, self.model, fk_name=self.fk_name, fields=fields, formfield_callback=self.formfield_for_dbfield, extra=self.extra)
     742        return forms.inline_formset(self.parent_model, self.model, fk_name=self.fk_name, fields=fields, formfield_callback=self.formfield_for_dbfield, extra=self.extra, formset=self.formset)
    742743
    743744    def formset_change(self, request, obj):
    744745        """Returns an InlineFormSet class for use in admin change views."""
    class InlineModelAdmin(BaseModelAdmin):  
    746747            fields = flatten_fieldsets(self.declared_fieldsets)
    747748        else:
    748749            fields = None
    749         return forms.inline_formset(self.parent_model, self.model, fk_name=self.fk_name, fields=fields, formfield_callback=self.formfield_for_dbfield, extra=self.extra)
     750        return forms.inline_formset(self.parent_model, self.model, fk_name=self.fk_name, fields=fields, formfield_callback=self.formfield_for_dbfield, extra=self.extra, formset=self.formset)
    750751
    751752    def fieldsets_add(self, request):
    752753        if self.declared_fieldsets:
  • django/newforms/models.py

    diff --git a/django/newforms/models.py b/django/newforms/models.py
    index 3a80517..ac9f2d9 100644
    a b def get_foreign_key(parent_model, model, fk_name=None):  
    408408            raise Exception("%s has more than 1 ForeignKey to %s" % (model, parent_model))
    409409    return fk
    410410
    411 def inline_formset(parent_model, model, fk_name=None, fields=None, extra=3, orderable=False, deletable=True, formfield_callback=lambda f: f.formfield()):
     411def inline_formset(parent_model, model, fk_name=None, fields=None, extra=3, orderable=False, deletable=True, formfield_callback=lambda f: f.formfield(), formset=None):
    412412    """
    413413    Returns an ``InlineFormset`` for the given kwargs.
    414414
    def inline_formset(parent_model, model, fk_name=None, fields=None, extra=3, orde  
    417417    """
    418418    fk = get_foreign_key(parent_model, model, fk_name=fk_name)
    419419    # let the formset handle object deletion by default
    420     FormSet = formset_for_model(model, formset=InlineFormset, fields=fields,
     420    FormSet = formset_for_model(model, formset=formset or InlineFormset, fields=fields,
    421421                                formfield_callback=formfield_callback,
    422422                                extra=extra, orderable=orderable,
    423423                                deletable=deletable)
Back to Top