Re: follow relationship

2006-04-03 Thread akaihola
http://code.djangoproject.com/wiki/CookBookChoicesContantsClass Feel free to fix any mistakes on the page! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: follow relationship

2006-04-02 Thread Ned Batchelder
Feel free to add it! --Ned. akaihola wrote: > Ned, I think this is definitely Django Cookbook stuff. It would perhaps > fit in http://code.djangoproject.com/wiki/CookBookDataModels > > I can add it for you if you're busy and allow me to... :) > > > > > > > . > > -- Ned Batchelder,

Re: follow relationship

2006-04-02 Thread akaihola
Ned, I think this is definitely Django Cookbook stuff. It would perhaps fit in http://code.djangoproject.com/wiki/CookBookDataModels I can add it for you if you're busy and allow me to... :) --~--~-~--~~~---~--~~ You received this message because you are

Re: follow relationship

2006-03-30 Thread Todd O'Bryan
Thanks a lot! I would have tried to do something with tuples, but this seems to make easy sense.ToddOn Mar 30, 2006, at 6:06 AM, Ned Batchelder wrote: Sorry, sent the email before the formatting was right: class K:     def __init__(self, label=None, **kwargs):     assert(len(kwargs) == 1)    

Re: follow relationship

2006-03-30 Thread Ned Batchelder
And there's a bug!  The body of choices() should be: def choices(self): return [(k.v, k.label) for k in self.klist] Ned Batchelder wrote: Sorry, sent the email before the formatting was right: class K:     def __init__(self, label=None, **kwargs):    

Re: follow relationship

2006-03-30 Thread Ned Batchelder
Sorry, sent the email before the formatting was right: 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

Re: follow relationship

2006-03-29 Thread Ned Batchelder
What I've done in these cases is to define a Constants class:     class Constants:     """ Construct one of these with keyword arguments, and you can use the     attributes.     """         def __init__(self, **kwargs):     for k, v in kwargs.items():    

Re: follow relationship

2006-03-29 Thread Ivan Sagalaev
Todd O'Bryan wrote: >Your comment at the end got me thinking, though. Writing > >trunk.get_branch(kind__exact=2) > >is not very illuminating, but you're correct that the value 'Dead' >could get changed later. In Java, I'd use constants for the integer >values > >public static final int DEAD

Re: follow relationship

2006-03-28 Thread Todd O'Bryan
On Mar 27, 2006, at 11:40 PM, Ivan Sagalaev wrote: > > Todd O'Bryan wrote: > >> The tutorial explains how to get objects based on field values, but I >> need to get a subset of the objects in a OneToMany relationship based >> on one of their values. Here's an example: >> >> BRANCH_KINDS = ((0,

Re: follow relationship

2006-03-27 Thread Ivan Sagalaev
Todd O'Bryan wrote: >The tutorial explains how to get objects based on field values, but I >need to get a subset of the objects in a OneToMany relationship based >on one of their values. Here's an example: > >BRANCH_KINDS = ((0, 'Main'), (1, 'Auxiliary'), (2, 'Dead'),) > >class

follow relationship

2006-03-27 Thread Todd O'Bryan
The tutorial explains how to get objects based on field values, but I need to get a subset of the objects in a OneToMany relationship based on one of their values. Here's an example: BRANCH_KINDS = ((0, 'Main'), (1, 'Auxiliary'), (2, 'Dead'),) class Trunk(meta.Model): name =