Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

276
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda