Opened 5 years ago

Last modified 5 years ago

#26983 closed Bug

models.Manager query "filter(field__isnull=False)" not working in 1.10 — at Initial Version

Reported by: weidwonder Owned by: nobody
Component: Database layer (models, ORM) Version: 1.10
Severity: Normal Keywords: queryset
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

models Manager:

class ModelManager(models.Manager):
    def get_queryset(self):
        return super(ModelManager, self).get_queryset().filter(parent__isnull=False)

models:

class Category(models.Model):
    parent = models.ForeignKey('Category', to_field='slug', db_column='parent',
                               max_length=32, blank=True, null=True,
                               related_name='models')
    name = models.CharField(max_length=50, blank=True, null=True)
    ....
    vehicle_models = ModelManager()

    class Meta:
        db_table = 'open_category'
        ordering = ['pinyin']

query:

Category.vehicle_models.filter(slug=model_slug).values('name').query

query's sql output is:

SELECT `open_category`.`name` FROM `open_category` WHERE (`open_category`.`parent` IS NULL AND `open_category`.`slug` = "suteng") ORDER BY `open_category`.`pinyin` ASC

it should be open_category.parent IS NOT NULL

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top