On Mon, Aug 27, 2012 at 6:36 AM, Axel Rau <axel....@chaos1.de> wrote:

> To clarify:
> --- from admin.py:
> class MailboxAdmin(admin.ModelAdmin):
>         list_display = ('localpart', 'localdomainfk', 'type',
> 'aliastargetaddresses', 'created', 'updated')
>         fieldsets = (
>                 (None, {
>                         'fields': (('localpart', 'localdomainfk'),
> 'accountfk', 'lifetime', 'type')
>                 }),
>                 (_('Mailbox'), {
>                         'classes': ('collapse',),
>                         'fields': ('aoxuserid', 'quota')
>                 }),
>                 (_('Alias'), {
>                         'classes': ('collapse',),
>                         'fields': ('aliastargetaddresses',)
>                 }),
>                 (None, {
>                         'fields': ('remarks',)
>                 })
>         )
>
> ...
> admin.site.register(Mailbox, MailboxAdmin)
>
> --- from models.py:
> class Mailbox(models.Model):
>     id = models.AutoField(primary_key=True)
>     localpart = models.CharField(_('Localpart'), max_length=40)
>     localdomainfk = models.ForeignKey(Localdomain,
>  verbose_name=_('Domainteil'), db_column='localdomainfk')
>     accountfk = models.ForeignKey(Account, db_column='accountfk')
>     aoxuserid = models.IntegerField(_('IMAP Server User ID'), null=True,
> blank=True)
>     serverpassword = NULLCharFieldM(_('Server Password'), null=True,
> blank=True, max_length=40)
>     quota = models.PositiveSmallIntegerField(_('IMAP Server
> Quota'),null=True, blank=True)
>     type = models.CharField('Typ', max_length=1, choices=
>         (('A', _('Alias')), ('M', _('Mailbox')), ('S', _('Systemalias'))))
>     aliastargetaddresses = NULLCharFieldM(_('Alias
> Targetaddress'),null=True, blank=True, max_length=60)
>     status = models.CharField(_('Status'), max_length=1, choices=
>         (('N', _('New')), ('E', _('Enabled')), ('L', _('Locked')), ('D',
> _('Disabled')), ('C', _('Closed'))),
>         default='N')
>     created = models.DateField(_('Created'), auto_now_add=True)
>     updated = models.DateField(_('Updated'), auto_now=True)
>     remarks = models.TextField(_('Remarks'),null=True, blank=True)
>     lifetime = TimedeltaDayFieldM(_('Lifetime of Data'), max_length=10)
>     class Meta:
>         db_table = u'mailbox'
>         verbose_name = _('Mailbox')
>         verbose_name_plural = _('Mailboxes')
>         ordering = ['localpart']
>         unique_together = ('localpart', 'localdomainfk')
>     def __unicode__(self):
>         return self.localpart+'@'+self.localdomainfk.name
> ---
> If the user selects 'Alias' or 'Systemalias' in the type choice, I would
> like to see the 'Alias' fieldset expanded.
> If he selects 'Mailbox', the fieldset 'Mailbox'.
>
> How can I do this in admin site?


Through JS, you need to implement a script that binds to the change event
and then changes the collapse css call for the specific div. You may want
to look
at jQuery, although this is out of scope of the list.

Once you have your script ready you need to tell your admin form to use it,
read this
it explains how you do that.

https://docs.djangoproject.com/en/dev/topics/forms/media/



> Axel
>
> Am 27.08.2012 um 01:11 schrieb Nicolas Emiliani:
>
> > On Sun, Aug 26, 2012 at 5:03 PM, Axel Rau <axel....@chaos1.de> wrote:
> >
> >> In my admin site, I have a fieldset which depends on a choice.
> >> I would like to control expansion of the related fieldset by the choice
> >> instead of the standard widgets.
> >> How can I do this?
> >>
> >
> > I don't understand clearly what you want, but, correct me if I'm wrong,
> you
> > have some field and by doing something on it, maybe selecting it ? you
> want
> > to something else on some other fields, maybe show/hide them ?
> >
> > If this is what you are looking for, you could use javascript to do the
> > magic, you can tell the admin form to use a specific js script and u can
> > even generate that js dynamically.
> >
> > If this is not helpful please be more specific.
> >
> >
> >
> >> Axel
> >> ---
> >> PGP-Key:29E99DD6  ☀ +49 151 2300 9283  ☀ computing @ chaos claudius
> >>
> >> --
> >> 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.
> >>
> >>
> >
> >
> > --
> > Nicolas Emiliani
> >
> > Lo unico instantaneo en la vida es el cafe, y es bien feo.
> >
> > --
> > 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.
> >
>
> ---
> PGP-Key:29E99DD6  ☀ +49 151 2300 9283  ☀ computing @ chaos claudius
>
> --
> 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.
>
>


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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.

Reply via email to