On 5 April 2012 09:45, Thomas Guettler <[email protected]> wrote:
> Hi,
>
> I created a ticket, incl. patch
>
> https://code.djangoproject.com/ticket/18062
>
>
While the example itself is useful, I don't really think Django's
documentation should state obvious facts about Python, especially
false ones.
>
> Am 04.04.2012 18:41, schrieb Adrian Holovaty:
>>
>>
>> I don't see the immediate need for Yet Another Sub-framework, as
>> described in this proposal. This is what I normally do, and it works
>> fine:
>>
>> class User(models.Model):
>> MALE = 0
>> FEMALE = 1
>> GENDERS = [(MALE, 'Male'), (FEMALE, 'Female')]
>> gender = models.IntegerField(choices=GENDERS)
>>
>> def greet(self):
>> return {MALE: 'Hi, boy', FEMALE: 'Hi, girl.'}[self.gender]
>>
I' sure you meant:
def greet(self):
return {self.MALE: 'Hi, boy', self.FEMALE: 'Hi, girl.'}[self.gender]
Unless you defined MALE/FEMALE as globals too :) Otherwise you'll get
a NameError.
--
Łukasz Rekucki
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.