On 28-8-2012 14:30, Axel Rau wrote: > > Am 28.08.2012 um 00:13 schrieb Melvyn Sopacua: > >>> >>> Another question: How can I expand the right fieldset dependent of >>> current content of my choices field (as loaded from db) while >>> rendering the change page initially? >> >> Look in django/contrib/admin/options.py for get_fieldsets(). Also look >> at this bugreport for it's limitations: >> <https://code.djangoproject.com/ticket/18681> >> >> Short version: the method as it is implemented requires that you have at >> least some declared fieldsets. >> >> In case you're also new to python, you should convert your declared >> fieldsets from a tuple to a list, so it's easier to modify it. > This method belongs to InlineModelAdmin. > I never worked with Inlines before. It seems, they work only with parent- > child situations (as documented). Unfortunately my form deals only with one > model.
Not sure why you would think that it only applies to inlines. It's a method for ModelAdmin (shared by InlineModelAdmin through inheritance). >>> from django.contrib.admin import ModelAdmin >>> ModelAdmin.get_fieldsets <unbound method ModelAdmin.get_fieldsets> Try this: class MailboxAdmin(models.ModelAdmin) : list_display = ('localpart', 'localdomainfk', 'type', 'aliastargetaddresses', 'created', 'updated') fieldsets = [ (None, { 'fields': (('localpart', 'localdomainfk'), 'accountfk', 'lifetime', 'type') }), ] def fieldset_section(self, title, fields, classes=None) : if classes is not None : return (title, { 'fields': fields, 'classes': classes } ) else : return (title, {'fields': fields}) def get_fieldsets(self, request, obj=None) : alias_classes = mailbox_classes = None if obj : if obj.type == 'A' : alias_classes = ('collapse',) elif obj.type == 'M' : mailbox_classes = ('collapse',) fs = self.declared_fieldsets fs.append(self.fieldset_section('Mailbox', ('aoxuserid', 'quota'), mailbox_classes)) fs.append(self.fieldset_section('Aliases', ('aliastargetaddresses',), alias_classes)) fs.append(self.fieldset_section(None, ('remarks',))) return fs -- Melvyn Sopacua -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.