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()


On Mar 30, 10:32 am, Thomas <thomasje...@gmail.com> wrote:
> Hi all,
>
> I try to get a list with distinct into the forms.py like this:
>
> forms.ModelMultipleChoiceField(queryset=Events.objects.values('hostname'),
> required=False).distinct()
>
> In the python shell this command works perfect, but when trying it in
> forms.py leaves me a blank form, so nothing appears. When i just do
> Events.objects.all() the form appears, but distinct doesn't work with
> Events.objects.all()... i also tried values_list etc but doesn't seem
> to fit into the forms neither... anyone got an idea how to get a
> SELECT DISTINCT into a ModelMultipleChoiceField?
>
> I read some other questions about this at stackoverflow but nothing
> seems to work out with me, so hopefully someone knows how to do this
> in forms.py.
>
> Thxs in advance

-- 
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