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
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,
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
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)
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):
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
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():
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
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,
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
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 =
11 matches
Mail list logo