3

I am trying to follow this documentation. I would like to pass somehow parameters to get_queryset, but don't know how. Not working demo below.

class ContextAwareNotificationsManager(models.Manager):

    def get_queryset(self, user):
        return super(ContextAwareNotificationsManager, self).get_queryset(user).filter((
            Q(kind='SYSTEM') | Q(kind='TODO', status=False)
        ), content_type__name__in=['publisher', 'site', 'channel']).order_by('-date')
andilabs
  • 22,159
  • 14
  • 114
  • 151
  • 1
    @petkostas's answer is the way to go, you should generally avoid overriding `get_query_set` and instead add your own methods that give you the queryset you're looking for. – Matt Jun 12 '14 at 10:48
  • 1
    @Matt: These days, overriding `get_queryset` does seem like the proper thing to do, generally, according to the [documentation](https://docs.djangoproject.com/en/3.0/topics/db/managers/#modifying-a-manager-s-initial-queryset). Just maybe not in this specific case. – djvg Jun 10 '20 at 19:20

1 Answers1

2

This should be what you are looking for:

class ContextAwareNotificationsManager(models.Manager):

    def filter_user(self, user):
        return super(ContextAwareNotificationsManager, self).get_query_set().filter(...)
petkostas
  • 7,250
  • 3
  • 26
  • 29