[Django]-Override Django User Manager to only return active users in queries

1πŸ‘

βœ…

It is a requirement to apply the filter to the User model? Why don’t you try to subclass this model instead?, and code a manager for this one.

class CustomUserManager(UserManager):

    def get_query_set(self):
        return super(CustomUserManager, self).get_query_set().
          filter(is_active=True)


class MyUser(User):
    objects = CustomUserManager()

# get an active user which username is 'foo'
MyUser.objects.get(username='foo')

or use a proxy model

πŸ‘€trinchet

0πŸ‘

Found the answer in this post. Since his question is specific and mine is general, I don’t consider them duplicates, but the answer to his question also answers mine.

πŸ‘€Clay Wardell

Leave a comment