[google-appengine] Re: Model field value choices - can the list be generated dynamically?

2009-01-21 Thread Waldemar Kornewald
Hi, On Jan 20, 5:49 pm, Janne Kuuskeri wrote: > > You can use a custom ModelChoiceField and override itslabel_from_instance() > > method: > > > class SizeOptionChoiceField(ModelChoiceField): > >     deflabel_from_instance(self, obj): > >         return obj.code > > Sorry, I'm a bit late to the

[google-appengine] Re: Model field value choices - can the list be generated dynamically?

2009-01-20 Thread Janne Kuuskeri
> You can use a custom ModelChoiceField and override itslabel_from_instance() > method: > > class SizeOptionChoiceField(ModelChoiceField): >     deflabel_from_instance(self, obj): >         return obj.code Sorry, I'm a bit late to the game but i just ran into this thread and wanted to ask that

[google-appengine] Re: Model field value choices - can the list be generated dynamically?

2008-12-30 Thread Martynas Brijunas
Gents, I cannot thank you enough for all your help. The community here is great and makes a n00b like me feel welcome. Happy New Year! Best regards, Martin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google Ap

[google-appengine] Re: Model field value choices - can the list be generated dynamically?

2008-12-29 Thread johnP
I initially implemented using __str__ (without much thought). Then in some cases, started seeing unicode decode errors in template views if a user inputs international characters. Switching to __unicode__ resolved this category of issues. That was the practical difference, for me, between __st

[google-appengine] Re: Model field value choices - can the list be generated dynamically?

2008-12-28 Thread Alexander Kojevnikov
> > your suggestions to override methods worked a treat. Overriding at the > > Model level suits me very well as it gives me flexibility. One final > > question (I hope): what is the difference in overriding the > > __unicode__ and __str__ methods? > > Unless you're actually dealing with Unicode t

[google-appengine] Re: Model field value choices - can the list be generated dynamically?

2008-12-28 Thread David Symonds
On Mon, Dec 29, 2008 at 12:24 AM, Martynas Brijunas wrote: >> Nice one! The alternative is to define a __str__ method on your >> SizeOption class, since that is what is used to render the options in >> the default label_from_instance implementation. Oops. I read Alex's email too quickly. He sug

[google-appengine] Re: Model field value choices - can the list be generated dynamically?

2008-12-28 Thread Martynas Brijunas
Hi Alex/David, > Alternatively, you can override the __unicode__ method of your model: > >class SizeOption(db.Model): >code = db.StringProperty(required = True) >html = db.StringProperty(required = True, multiline = True) > >def __unicode__(self): >return self.code > > You ca

[google-appengine] Re: Model field value choices - can the list be generated dynamically?

2008-12-27 Thread David Symonds
On Sun, Dec 28, 2008 at 9:02 AM, Alexander Kojevnikov wrote: > You can use a custom ModelChoiceField and override its > label_from_instance() method: Nice one! The alternative is to define a __str__ method on your SizeOption class, since that is what is used to render the options in the default

[google-appengine] Re: Model field value choices - can the list be generated dynamically?

2008-12-27 Thread Alexander Kojevnikov
> thank you very much for your suggestion to use the RefrenceProperty. I > am halfway there now. The Product form now displays a dropdown. > However, I am not really clear on how to specify what will be > displayed in that dropdown. Here is what it is displaying currently > when you open a dropdow

[google-appengine] Re: Model field value choices - can the list be generated dynamically?

2008-12-27 Thread Martynas Brijunas
Hi Consultuning/David, > You probably want to use a ReferenceProperty to a Colour entity in > your Product model. Then, customise your form something like this: > > class ProductEntryForm(djangoforms.ModelForm): > class Meta: > model = Product > > colour = djangoforms.ModelChoiceField(Col

[google-appengine] Re: Model field value choices - can the list be generated dynamically?

2008-12-27 Thread David Symonds
On Sat, Dec 27, 2008 at 10:07 PM, Martynas Brijunas wrote: > Why am I doing this? It is because I want to use it with the > db.djangoforms.ModelForm class. If I have a list of choices for a > field, the ModelForm automatically gives me a dropdown. If there is no > list of choices all I get is a

[google-appengine] Re: Model field value choices - can the list be generated dynamically?

2008-12-27 Thread Consultuning
I think that the best way to address your problem would be using a ReferenceProperty to another object type where you list all the colors you wish to present as choices, does that work? --~--~-~--~~~---~--~~ You received this message because you are subscribed to t