Django QuerySets: Fucking Awesome? Yes

Django QuerySets are pretty awesome.

In this post I’ll explain a bit about what they are and how they work (if you’re already familiar with them, you can jump to the second part), I’ll argue that you should always return a QuerySet object if it’s possible and I’ll talk about how to do just that.


This is a companion discussion topic for the original entry at http://amir.rachum.com/blog/2013/07/13/django-querysets-fucking-awesome-yes/

The only thing I'd like is for querysets + managers to be the merged - so that your custom methods could appear anywhere in the query chain.

I agree. A built-in Django mechanism for allowing QuerySet extension with manager pass-through methods would be great.

Try the PassThroughManager from django-model-utils: https://github.com/carljm/djan...

Show us models.py to make things a lil clearer

Thanks for the query difference tip, it was the straight forward answer what I was looking for.

Thanks for the clean intersection explanation. Answered my google query ;)

That's great, but I came to the site to find out if I can use querySet in a similar fashion to a join. In other words I have a db table (model) with some id value attributes. Those id's point to another table that holds values. I want to join the model to another model to resolve the normalization I did on the database before I migrated it. Now I have a querySet of rows, but some of the attributes are just foreign key values, and I'd like to resolve those against the other models...