Django Distinct on queryset in forms.py

Posted by Thomas on Stack Overflow See other posts from Stack Overflow or by Thomas
Published on 2010-03-30T08:11:35Z Indexed on 2010/03/30 8:13 UTC
Read the original article Hit count: 324

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about django

Related posts about distinct