I want to exclude non-active users from my project.
example 1:
url:users/1/friends/ will show all friends of that user.
I want to show only a
You should use a custom Model Manager:
class ActiveUsersManager(models.Manager):
use_for_related_fields = True
def get_queryset(self):
return super(ActiveUserManager, self).get_queryset().filter(is_active=True)
class User(models.Model):
is_active = models.BooleanField(default=true)
# first manager is the default and accessible through objects.
active = ActiveUsersManager()
all_users = models.Manager()
active_users = User.objects.all()
all_users = User.all_users.all()