Filtering out results in Automatic Managers

18 views
Skip to first unread message

Shubham Jain

unread,
Jan 3, 2014, 5:03:13 PM1/3/14
to django...@googlegroups.com
Hi,

"A manager that filters results in get_queryset() is not appropriate for use as an automatic manager."

Can you please tell me why is it not appropriate because this is exactly what I want, filter results in backward RelatedManagers?

It is written, "If you override the get_queryset() method and filter out any rows, Django will return incorrect results.". What type of incorrect results will Django return?

Thank you


Example:

class TrashableManager(models.Manager):
    use_for_related_fields = True
    def get_query_set(self):
        return super(TrashableManager, self).get_query_set().filter(trashed=False)

class TrashedManager(models.Manager):
    def get_query_set(self):
        return super(TrashableManager, self).get_query_set().filter(trashed=True)

class Trashable(models.Model):
    trashed = models.BooleanField(default=False)
    datetime_trashed = models.DateTimeField(blank=True, null=True)
    objects = TrashableManager()
    trashed_objects = TrashedManager()

    def trash(self):
        if not self.trashed:
            self.datetime_trashed = datetime.now()
        self.trashed = True
        self.save()

    class Meta:
        abstract = True
Reply all
Reply to author
Forward
0 new messages