Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
How to disable access to a django APIs based on is_active boolean field?

I have an author's model with a field:

is_active = models.BooleanField(default=False)

I wish to restrict access to the author whose is_active=False.

I can use something like this in every api:

get_object_or_404(uuid=id, is_active=True)

But I wish to globally restrict access to the UUID whose is_active=false, instead of actually writing this statement in every api.

Is there a way I can do that?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can create a custom permission class and use it as permission class, where you will check if the user is authenticated and also an active member.

Something like this :

class UserIsActive(permissions.BasePermission):

    def has_permission(self, request, view):
        if request.user.is_authenticated and request.user.is_active:
            return True
        return False

    def has_object_permission(self, request, view, obj):
        if request.user.is_active:
            return True
        return False

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!