Hi,
try this:
**********
resultList =
list(
set(modelList) &
set(Model1.objects.filter(model2__pk__isnull = False).distinct
())
)
**********
or this:
**********
resultList =
list(
set(modelList) &
set([m.model1 for m in Model2.objects.all()])
)
**********
Both solutions are equivalent, I think, and are exactly what you need
- I hope :-)
Matus
On Jan 29, 10:29 am, Odd <[email protected]> wrote:
> Hmm...
>
> After a little testing, this is not what I wanted, some of the model1
> objects in the return_list was not in the provided modelList, and I
> dont't quite understand why they are returned. As stated before, I
> want to get a distinct list of all model1 objects that is in a
> provided list and is used as a foreignkey in any model2 object. Is
> this doable?
>
> Thanks.
--
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.