Do you want, as your first posting says, to select players not on your
team, that is,
have a queryset that returns such, or do you want a single or multi-select field
on a form having those players, as playing with self.field['members'] in your
second post would seem to imply?

You need the first in either case.  Maybe:

   q = Player.objects.exclude(team_set__contains=this_team)

Then, for the second part, ModelChoiceField and ModelMultipleChoiceField
accept a constructor keyword argument named queryset.

On Sat, May 1, 2010 at 1:34 PM, Kenneth Gonsalves <[email protected]> wrote:
> On Saturday 01 May 2010 10:54:52 pm Kenneth Gonsalves wrote:
>> I have a model called 'Team' with a manytomany field to 'Player'. How do I
>> select all the players who are not in any team? I remember doing this
>>  once,  but cannot find what I did.
>>
>
> I have tried this:
> self.fields['members'].choices = [(x.id,x.name) for x in Player.objects.all()
> if x.team_set.all() == []]
>
> does not seem very elegant
> --
> regards
> Kenneth Gonsalves
> Senior Associate
> NRC-FOSS
> http://certificate.nrcfoss.au-kbc.org.in
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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

Reply via email to