Ticket #12238: dynamic-fieldsets-0.1.diff

File dynamic-fieldsets-0.1.diff, 1.9 KB (added by Batiste Bieler, 15 years ago)

Attempt to use dynamic fieldsets generation

  • django/contrib/admin/options.py

     
    5858    fields = None
    5959    exclude = None
    6060    fieldsets = None
     61    dynamic_fieldsets = None
    6162    form = forms.ModelForm
    6263    filter_vertical = ()
    6364    filter_horizontal = ()
     
    318319
    319320    def get_fieldsets(self, request, obj=None):
    320321        "Hook for specifying fieldsets for the add form."
     322        if self.dynamic_fieldsets:
     323            self.dynamic_fieldsets(request, obj)
    321324        if self.declared_fieldsets:
    322325            return self.declared_fieldsets
    323326        form = self.get_form(request, obj)
     
    328331        Returns a Form class for use in the admin add view. This is used by
    329332        add_view and change_view.
    330333        """
    331         if self.declared_fieldsets:
     334        if self.dynamic_fieldsets:
     335            fields = flatten_fieldsets(self.dynamic_fieldsets(request, obj, **kwargs))
     336        elif self.declared_fieldsets:
    332337            fields = flatten_fieldsets(self.declared_fieldsets)
    333338        else:
    334339            fields = None
     
    11361141
    11371142    def get_formset(self, request, obj=None, **kwargs):
    11381143        """Returns a BaseInlineFormSet class for use in admin add/change views."""
     1144        if self.dynamic_fieldsets:
     1145            fields = flatten_fieldsets(self.dynamic_fieldsets(request, obj))
    11391146        if self.declared_fieldsets:
    11401147            fields = flatten_fieldsets(self.declared_fieldsets)
    11411148        else:
     
    11601167        return inlineformset_factory(self.parent_model, self.model, **defaults)
    11611168
    11621169    def get_fieldsets(self, request, obj=None):
     1170        if self.dynamic_fieldsets:
     1171            return self.dynamic_fieldsets(request, obj)
    11631172        if self.declared_fieldsets:
    11641173            return self.declared_fieldsets
    11651174        form = self.get_formset(request).form
Back to Top