thanks for your advise daniel, is see it now and the hint with values_list works great.
thanks again On 4 Mai, 13:11, Daniel Roseman <[email protected]> wrote: > On May 4, 9:53 am, danfis <[email protected]> wrote: > > > > > > > Hi guys, > > > i ran into a problem today which i'm not sure if it's a bug (or a > > feature?!) so you might can help me: > > > when i call a model manager method to manipulate the queryset and > > using Q objects for filtering, it seems like the query of the method > > (=queryset.query) "stores" the result of subqueries and not the > > subquery itself. > > this causes, of course, into some 'old' data sometimes, so i wondered > > if this is correct? > > > a simple example: > > this is the manager for my model Bar and there is also some other > > model having a foreign key to this one > > > def get_my_stuff(self): > > return self.filter(Q(field_1='foobar') | Q(pk__in=[foo.bar_id for > > foo in SomeOtherModel.objects.all()]) > > > the problem is now, that the result of the subquery ([foo.bar_id for > > foo in SomeOtherModel.objects.all()]) is stored as fixed value (and > > not as subquery) in the query and changes in SomeOtherModel objects > > are not recognized correctly. > > > Any advises? > > This is expected, because you're explicitly evaluating the result of > SomeOtherModel.objects.all(), thanks to your list comprehension. Using > values_list is probably better, as that produces a lazy > ValuesListQuerySet: > > Q(pk__in=SomeOtherModel.values_list('bar_id', flat=True)) > -- > DR. > > -- > 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 > athttp://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.

