Re: Distinct Values in ModelChoiceField

2012-08-23 Thread Joseph Mutumi
@Melvyn Thank you. It actually worked out as you said. It needed a redesign. On Wed, Aug 22, 2012 at 1:44 PM, Sithembewena Lloyd Dube wrote: > @Melvyn, thanks - that makes sense. > > > On Wed, Aug 22, 2012 at 3:18 AM, Melvyn Sopacua wrote: > >> On

Re: Distinct Values in ModelChoiceField

2012-08-22 Thread Sithembewena Lloyd Dube
@Melvyn, thanks - that makes sense. On Wed, Aug 22, 2012 at 3:18 AM, Melvyn Sopacua wrote: > On 22-8-2012 3:04, Sithembewena Lloyd Dube wrote: > > > I found your response to the OP interesting, yet I cannot quite follow > it. > > Even if he sets a unique attribute

Re: Distinct Values in ModelChoiceField

2012-08-21 Thread Melvyn Sopacua
On 22-8-2012 3:04, Sithembewena Lloyd Dube wrote: > I found your response to the OP interesting, yet I cannot quite follow it. > Even if he sets a unique attribute (presumably Boolean/ Checkbox?) Nope, this unique attribute: By

Re: Distinct Values in ModelChoiceField

2012-08-21 Thread Sithembewena Lloyd Dube
Hi Melvyn, I found your response to the OP interesting, yet I cannot quite follow it. Even if he sets a unique attribute (presumably Boolean/ Checkbox?), he would still need a mechanism to filter the result set at runtime? Please expound? On Mon, Aug 20, 2012 at 11:12 AM, Melvyn Sopacua

Re: Distinct Values in ModelChoiceField

2012-08-20 Thread Melvyn Sopacua
On 20-8-2012 0:16, Joseph Mutumi wrote: > That particular field at times appears multiple times in the database. How > do I make it > only have distinct values? > > This is a snippet, drop down will have repeated values if same color is > entered: > > class FavoriteColor(models.Model): >

Re: Distinct Values in ModelChoiceField

2012-08-19 Thread Sithembewena Lloyd Dube
I reckon you could try the following: - declare a function which does a 'select distinct' and returns the queryset via the ORM e.g. def distinct_colors(): results = FavoriteColor.objects.all().values("color").distinct() return results then ... class FavoriteThingsForm(forms.ModelForm):

Distinct Values in ModelChoiceField

2012-08-19 Thread Joseph Mutumi
Hello, I have a model that has a foreign key field that I want to use in a form as a select box. That particular field at times appears multiple times in the database. How do I make it only have distinct values? This is a snippet, drop down will have repeated values if same color is entered: