django-orm

approaching models from the other side of a foreign key

Working with Django docs' sample Blog and Entry models, how would one get a queryset of all Blog objects that have name = "a" and that are not associated with any instance of the Entry model? In raw (My)SQL terms, what is the Django ORM equivalent of: SELECT * FROM blog_table bt WHERE bt.name='a' AND bt.id NOT IN (SELECT et.blog_id FRO...

Django ORM: count a subset of related items

I am looking to find a way to annotate a queryset with the counts of a subset of related items. Below is a subset of my models: class Person(models.Model): Name = models.CharField(max_length = 255) PracticeAttended = models.ManyToManyField('Practice', through = 'PracticeRecord') cl...

Django __in lowercase

Hi there, I'm using django-taggit, which handles the attachment of tags to arbitrary content types. I imported a large tag list, which contains many uppercase words, as well as lowercase words. Now, I' trying to get objects of another class containing a set of tags, but I want to compare case insensitively. When I do this: Media.objec...

Move a python / django object from a parent model to a child (subclass)

I am subclassing an existing model. I want many of the members of the parent class to now, instead, be members of the child class. For example, I have a model Swallow. Now, I am making EuropeanSwallow(Swallow) and AfricanSwallow(Swallow). I want to take some but not all Swallow objects make them either EuropeanSwallow or AfricanSwall...