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
|
|
1 | 1 | from django import oldforms, template |
2 | 2 | from django import newforms as forms |
3 | 3 | from django.newforms.formsets import all_valid |
4 | | from django.contrib.contenttypes.models import ContentType |
5 | 4 | from django.contrib.admin import widgets |
6 | 5 | from django.contrib.admin.util import get_deleted_objects |
7 | 6 | from django.core.exceptions import ImproperlyConfigured, PermissionDenied |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
451 | 450 | return HttpResponseRedirect("../") |
452 | 451 | |
453 | 452 | def render_change_form(self, model, context, add=False, change=False, form_url=''): |
| 453 | from django.contrib.contenttypes.models import ContentType |
454 | 454 | opts = model._meta |
455 | 455 | app_label = opts.app_label |
456 | 456 | ordered_objects = opts.get_ordered_objects() |
… |
… |
class InlineModelAdmin(BaseModelAdmin):
|
721 | 721 | template = None |
722 | 722 | verbose_name = None |
723 | 723 | verbose_name_plural = None |
| 724 | formset = None |
724 | 725 | |
725 | 726 | def __init__(self, parent_model, admin_site): |
726 | 727 | self.admin_site = admin_site |
… |
… |
class InlineModelAdmin(BaseModelAdmin):
|
738 | 739 | fields = flatten_fieldsets(self.declared_fieldsets) |
739 | 740 | else: |
740 | 741 | 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) |
742 | 743 | |
743 | 744 | def formset_change(self, request, obj): |
744 | 745 | """Returns an InlineFormSet class for use in admin change views.""" |
… |
… |
class InlineModelAdmin(BaseModelAdmin):
|
746 | 747 | fields = flatten_fieldsets(self.declared_fieldsets) |
747 | 748 | else: |
748 | 749 | 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) |
750 | 751 | |
751 | 752 | def fieldsets_add(self, request): |
752 | 753 | if self.declared_fieldsets: |
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):
|
408 | 408 | raise Exception("%s has more than 1 ForeignKey to %s" % (model, parent_model)) |
409 | 409 | return fk |
410 | 410 | |
411 | | def inline_formset(parent_model, model, fk_name=None, fields=None, extra=3, orderable=False, deletable=True, formfield_callback=lambda f: f.formfield()): |
| 411 | def inline_formset(parent_model, model, fk_name=None, fields=None, extra=3, orderable=False, deletable=True, formfield_callback=lambda f: f.formfield(), formset=None): |
412 | 412 | """ |
413 | 413 | Returns an ``InlineFormset`` for the given kwargs. |
414 | 414 | |
… |
… |
def inline_formset(parent_model, model, fk_name=None, fields=None, extra=3, orde
|
417 | 417 | """ |
418 | 418 | fk = get_foreign_key(parent_model, model, fk_name=fk_name) |
419 | 419 | # 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, |
421 | 421 | formfield_callback=formfield_callback, |
422 | 422 | extra=extra, orderable=orderable, |
423 | 423 | deletable=deletable) |