jazzband/django-model-utils

Filter InheritanceQuerySet by child field

gekmcfh opened this issue · 0 comments

Problem

I would like to clarify - if i have some child model field like boolean 'grill' for instance, in the Bar class.
Should that construct work? Place.objects.select_subclasses().filter(grill__isnull=False) ?
Because now i get an error: django.core.exceptions.FieldError: Cannot resolve keyword 'grill' into field.' Choices are: (...further all PARENT fields listed)

Environment

  • Django Model Utils version:4.1.1
  • Django version: 2.2.24
  • Python version: 3.7.5
  • Other libraries used, if any:

Code examples

from model_utils.managers import InheritanceManager

class Place(models.Model):
    # ...
    objects = InheritanceManager()

class Restaurant(Place):
    # ...

class Bar(Place):
    grill = models.BooleanField(default=False)

nearby_places = Place.objects.select_subclasses().filter(grill__isnull=False)