Re: Ticket for Docs improvement Was: Proposal: upgrading the choices machinery for Django

2012-04-05 Thread Alex Ogier
Interesting, you are right. It's still a little strange to me to be accessing class attributes via the self object, but I suppose it is more flexible than accessing them as User.MALE etc. which would make renaming the class awkward. Best, Alex Ogier On Apr 5, 2012 2:16 PM, "Łukasz Rekucki" wrote:

Re: Ticket for Docs improvement Was: Proposal: upgrading the choices machinery for Django

2012-04-05 Thread Łukasz Rekucki
On 5 April 2012 19:45, Alex Ogier wrote: > >> >> 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'

Re: Ticket for Docs improvement Was: Proposal: upgrading the choices machinery for Django

2012-04-05 Thread Alex Ogier
> >> 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

Re: Proposal: upgrading the choices machinery for Django

2012-04-05 Thread Tom Evans
2012/4/4 Łukasz Langa : > Wiadomość napisana przez Tom Evans w dniu 4 kwi 2012, o godz. 18:40: > >> The class definition grates. When we say things like: >> >>  class Gender(Choices): >>    male = Choice("male") >> >> That says to me that Gender.male is mutable. Ick. > > Thanks for your feedback. D

Re: Ticket for Docs improvement Was: Proposal: upgrading the choices machinery for Django

2012-04-05 Thread Thomas Guettler
Am 05.04.2012 10:03, schrieb Łukasz Rekucki: On 5 April 2012 09:45, Thomas Guettler 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 Pyt

Re: Proposal: upgrading the choices machinery for Django

2012-04-05 Thread Łukasz Langa
Wiadomość napisana przez Stephen Burrows w dniu 5 kwi 2012, o godz. 07:41: > I generally like this idea, except for the implicit integer ids based > on declaration order. Thanks for your input. I will add the ability to explicitly set .id values for each Choice in the next release. > As people

Re: Ticket for Docs improvement Was: Proposal: upgrading the choices machinery for Django

2012-04-05 Thread Łukasz Langa
Wiadomość napisana przez Łukasz Rekucki w dniu 5 kwi 2012, o godz. 10:03: > 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. Also, a minor d

Re: Ticket for Docs improvement Was: Proposal: upgrading the choices machinery for Django

2012-04-05 Thread Łukasz Rekucki
On 5 April 2012 09:45, Thomas Guettler 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

Ticket for Docs improvement Was: Proposal: upgrading the choices machinery for Django

2012-04-05 Thread Thomas Guettler
Hi, I created a ticket, incl. patch https://code.djangoproject.com/ticket/18062 Am 04.04.2012 18:41, schrieb Adrian Holovaty: 2012/4/3 Łukasz Langa: Explicit choice values:: GENDER_MALE = 0 GENDER_FEMALE = 1 GENDER_NOT_SPECIFIED = 2 GENDER_CHOICES = ( (GENDER_MALE, _('male')

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Stephen Burrows
I generally like this idea, except for the implicit integer ids based on declaration order. As people have said, it seems like just asking for data corruption. I'd much rather see implicit character ids based on the attribute name of the choice, analogous to django fields. Will you be making this

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Alex Ogier
On Wed, Apr 4, 2012 at 5:18 PM, Łukasz Langa wrote: > Wiadomość napisana przez Daniel Greenfeld w dniu 4 kwi 2012, o godz. 22:48: > > > On two occasions now I've had to do serious debugging on implementations > done by other people who used a technique not dissimilar to what Łukasz > proposes. In

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Łukasz Langa
Wiadomość napisana przez Daniel Greenfeld w dniu 4 kwi 2012, o godz. 22:48: > +1 to what Adrian says. Thanks for your input! :) > On two occasions now I've had to do serious debugging on implementations done > by other people who used a technique not dissimilar to what Łukasz proposes. > In bo

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Daniel Greenfeld
On Wednesday, April 4, 2012 9:41:23 AM UTC-7, Adrian Holovaty wrote: > 2012/4/3 Łukasz Langa : > > Explicit choice values:: > > > > GENDER_MALE = 0 > > GENDER_FEMALE = 1 > > GENDER_NOT_SPECIFIED = 2 > > > > GENDER_CHOICES = ( > > (GENDER_MALE, _('male')), > > (GENDER_FEMALE, _('femal

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Łukasz Langa
Wiadomość napisana przez Adrian Holovaty w dniu 4 kwi 2012, o godz. 18:41: > Also, the fact that we *don't* have a sub-framework for this lets > people do whatever they want -- including using the dj.choices module. > So I am -1 on including this in Django proper. Thank you for your feedback. As

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Łukasz Langa
Wiadomość napisana przez Tom Evans w dniu 4 kwi 2012, o godz. 18:40: > The class definition grates. When we say things like: > > class Gender(Choices): >male = Choice("male") > > That says to me that Gender.male is mutable. Ick. Thanks for your feedback. Do model and form field definitions

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Łukasz Langa
Wiadomość napisana przez Daniel Sokolowski w dniu 4 kwi 2012, o godz. 17:52: > The choice filtering could come in handy and in the end I don't see why this > can't co-exist with django's standard way. > > WAY 4: Nice but very verbose. -- Best regards, Łukasz Langa Senior Systems Architecture

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Sean Brant
I agree we don't really gain anything from including this in core. Django model utils[1] has a pretty solid implementation of a choice abstraction. [1] https://github.com/carljm/django-model-utils On Wed, Apr 4, 2012 at 11:41 AM, Adrian Holovaty wrote: > 2012/4/3 Łukasz Langa : >> Explicit choic

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Adrian Holovaty
2012/4/3 Łukasz Langa : > Explicit choice values:: > >  GENDER_MALE = 0 >  GENDER_FEMALE = 1 >  GENDER_NOT_SPECIFIED = 2 > >  GENDER_CHOICES = ( >      (GENDER_MALE, _('male')), >      (GENDER_FEMALE, _('female')), >      (GENDER_NOT_SPECIFIED, _('not specified')), >  ) > >  class User(models.Model

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Tom Evans
2012/4/3 Łukasz Langa : > A nice HTML rendering of this proposal is available at: > http://lukasz.langa.pl/2/upgrading-choices-machinery-django/ Disclaimer: all my code currently looks like 'Way 3'. In general, I like it. There are a few things I don't like in it: The class definition grates. Wh

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Daniel Sokolowski
ge----- From: Łukasz Langa Sent: Wednesday, April 04, 2012 9:15 AM To: django-developers@googlegroups.com Subject: Re: Proposal: upgrading the choices machinery for Django Wiadomość napisana przez Dan Poirier w dniu 4 kwi 2012, o godz. 14:08: One nice addition would be to specify explicitly w

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Łukasz Langa
Wiadomość napisana przez Thomas Guettler w dniu 4 kwi 2012, o godz. 15:55: > since most people have something like this in their code, a better solution > should require > only some additional characters. Thank you for your feedback. I disagree since it wouldn't address any of the original conc

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Thomas Guettler
Am 03.04.2012 21:31, schrieb Łukasz Langa: A nice HTML rendering of this proposal is available at: http://lukasz.langa.pl/2/upgrading-choices-machinery-django/ == Upgrading the choices machinery for Django == ...

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Łukasz Langa
Wiadomość napisana przez Dan Poirier w dniu 4 kwi 2012, o godz. 14:08: > One nice addition would be to specify explicitly what .id a particular > Choice should have. It would be useful in converting existing code that > might not have chosen to number its choices the same way this proposal > does

Re: Proposal: upgrading the choices machinery for Django

2012-04-04 Thread Dan Poirier
I like this - it solves something that's always bugged me. One nice addition would be to specify explicitly what .id a particular Choice should have. It would be useful in converting existing code that might not have chosen to number its choices the same way this proposal does by default. It looks

Proposal: upgrading the choices machinery for Django

2012-04-03 Thread Łukasz Langa
A nice HTML rendering of this proposal is available at: http://lukasz.langa.pl/2/upgrading-choices-machinery-django/ == Upgrading the choices machinery for Django == Specifying choices for form fields and models cur