The choices= attribute in the model defines what goes into the select
box. In this case, Constants.choices() returns a list based on the
values based to the Constants constructor. My example below has it
backwards for integers. It should be:def choices(self): return [(v,k) for k,v in self.__dict__.items()] Then for our example, the choices for Branch.kind would be [(1, 'main'), (2, 'aux'), (3, 'dead')], showing 'main', 'aux', 'dead' in the admin interface. Nicer labels than the Python identifiers wouldn't be possible with this code, you'd have to do something more elaborate: class K: def __init__(self, label=None, **kwargs): assert(len(kwargs) == 1) for k, v in kwargs.items(): self.id = k self.v = v self.label = label or self.id class Constants: def __init__(self, *args): self.klist = args for k in self.klist: setattr(self, k.id, k.v) def choices(self): return [(k.id, k.label) for k in self.klist] kBranchKind = Constants( K(main=1, label='Main branch'), K(dead=2, label='An ex-branch'), K(aux=3) # I don't know how to spell 'Auxilliary' anyway! ) Todd O'Bryan wrote: Wait. How do I define the user-friendly stuff that will show up in the select box for the admin interface? -- Ned Batchelder, http://nedbatchelder.com --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~--- |
- Re: follow relationship Ned Batchelder
- Re: follow relationship Ned Batchelder
- Re: follow relationship Ned Batchelder
- Re: follow relationship akaihola
- Re: follow relationship Ned Batchelder
- Re: follow relationship akaihola
- Re: follow relationship Todd O'Bryan