I'm trying to do this:
wider_circle = # some queryset
friends_you_may_know = list(wider_circle.exclude(user_id__in=user.connections))
But I'm getting this error:
RemovedInDjango19Warning: Passing callable arguments to queryset is deprecated
It worked on Django 1.6 but throws an error on 1.8
Thanks :)
This is because a Django QuerySet is a lazy object. It contains all of the information it needs to populate itself from the database, but will not actually do so until the information is needed.
Use union operator for queryset | to take union of two queryset. If both queryset belongs to same model / single model than it is possible to combine querysets by using union operator. One other way to achieve combine operation between two queryset is to use itertools chain function.
To create multiple records based on a Django model you can use the built-in bulk_create() method. The advantage of the bulk_create() method is that it creates all entries in a single query, so it's very efficient if you have a list of a dozen or a hundred entries you wish to create.
I'm assuming that connections
is a Many to Many on the user model. Which means that user.connections
is an instance of the related manager. You should try passing a queryset
instance ie:
friends_you_may_know = list(wider_circle.exclude(user_id__in=user.connections.all()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With