Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django polymorphic model, filter on subclass field

I have some models using django-polymorphic-model

eg.

class Article(PolymorphicModel):
  ...
class Blog(Article):
  tags = ...
class Story(Article):
  publish = ...

Normally if I get all articles, I just do Article.objects.all(), however what if I want to get all articles that tags are empty? If I do Articles.objects.filter(tags__isnull=True) it will break because other models don't have this field, I would like to include Story entries too, do I really have to split into 2 different queries and combine again?

like image 642
James Lin Avatar asked Mar 25 '23 07:03

James Lin


1 Answers

OK After some digging for the documentation through issues, here is how to do it

Articles.objects.filter(Blog___tags__isnull=True)
like image 57
James Lin Avatar answered Mar 30 '23 00:03

James Lin