actually, you need to do something like this:
user_stations = u.get_profile().station.all().values_list('pk',
flat=True)
excluded_stations = Station.objects.exclude(id__in=user_station_pks)
all_terrestrial_active_orders = Order.objects.filter(order_type=0,
in_market=True, end_date__gte=today)
terrestrial_active_orders = all_terrestrial_active_orders.exclude
(station__in=excluded_terrestrial_stations)
On Jun 4, 3:05 pm, ryan <[email protected]> wrote:
> answering my own question, seems like:
>
> Order.objects.filter(Q(station=1), Q(station=2), Q(station=3))
>
> -ryan
>
> On Jun 4, 2:29 pm, ryan <[email protected]> wrote:
>
> > #models.py
> > class Station(models.Model):
> > station_name = models.CharField(max_length=20)
>
> > class Order(models.Model):
> > station = models.ManyToManyField(Station, blank=True, null=True)
>
> > class UserProfile(models.Model):
> > user = models.ForeignKey(User, unique=True)
> > station = models.ManyToManyField(Station, blank=True, null=True)
>
> > >>> from myapp.models import Station, Order
> > >>> from django.contrib.auth.models import User
> > >>> u = User.objects.get(username__exact='ryan')
> > >>> user_stations = u.get_profile().station.all().values_list('pk',
> > >>> flat=True)
> > >>> user_stations
> > [1L, 2L, 3L]
> > >>> o = Order.objects.filter(station__in=user_stations)
> > >>> o
>
> > [Too many orders!]
>
> > Order.objects.filter(station__in=user_stations) returns any order
> > where any of its stations are in user_stations. What I need is only
> > those orders where ALL of its stations are in user_stations. Is there
> > a way to specify __all__in: Order.objects.filter
> > (station__all__in=user_stations)
>
> > -ryan
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---