Dear,

Look at my first post i had .distinct() into it and it didn't work
out, it's pretty obvious why, he does the distinct on the primary key
field (ID) and not on the field hostname, so i get no SELECT Distinct
result as i would like to. Trust me the only way of doing this is my
2nd post or the following should work aswell:
choices=Test.objects.values_list('hostname', 'hostname').distinct() ,
required=False

Regards

On Mar 30, 5:47 pm, "pjrhar...@gmail.com" <pjrhar...@gmail.com> wrote:
> On Mar 30, 2:10 pm, Thomas <thomasje...@gmail.com> wrote:
>
> > I already found a solution by myself:
>
> > doing this into the forms.py inside the class does the trick:
>
> >         def __init__(self, *args, **kwargs):
> >                 super(FilterForm, self) .__init__(*args, **kwargs)
> >                 self.fields['host'].choices =
> > Test.objects.values_list('hostname', 'hostname').distinct()
>
> You don't need anything that complicated, the original code just had a
> mistake- you need to put the ".distinct()" at the end of the query,
> not the field definition!
>
> Compare:
>
> orms.ModelMultipleChoiceField(queryset=Events.objects.values('hostname'),
> required=False).distinct()
>
> and:
>
> orms.ModelMultipleChoiceField(queryset=Events.objects.values('hostname').distinct(),
> required=False)
>
> Peter

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to