soy bastante nuevo usando django actualmente necesito obtener un query que me permita identificar por categoría cuantos usuarios existen, ejemplo: imaginemos que tenemos la siguientes categorias:
Docente Profesores
No Docente Técnicos educativos
No Docente Enfermera
No Docente Administrativo
No Docente Fisioterapeuta
No Docente Integrador Social
lo que necesito es utilizando un queryset ,determinar cuantos usarios son , Profesores, Fisio, etc, etc.
Aqui os dejo los modelos:
class User ( AbstractUser ) : # Extendind the User django model
id = models.UUIDField ( primary_key=True, default=uuid.uuid4, editable=False )
username = None
email = models.EmailField ( 'email address', unique=True )
observation = models.CharField ( max_length=230, null=True, blank=True )
is_account = models.BooleanField ( default=False )
is_signup = models.BooleanField ( default=False )
created_at = models.DateTimeField ( auto_now_add=True, null=True )
center = models.ForeignKey ( Center, null=True, on_delete=models.CASCADE )
#category = models.OneToOneField ( CenterUserCategory, null=True, default=None,on_delete=models.SET_NULL)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
objects = CustomUserManager ()
class Meta :
db_table = 'auth_user'
def __str__(self) :
return self.first_name
class CenterUserCategory ( models.Model ) :
USER_TYPE = (
('D', 'Docente'),
('N', 'No docente'),
('O', 'Otro'),
)
id = models.UUIDField ( primary_key=True, default=uuid.uuid4, editable=False )
category = models.CharField ( max_length=1, choices=USER_TYPE, verbose_name='Categoria de Usuario' )
description = models.CharField ( max_length=230, null=True, blank=False )
center = models.ForeignKey ( Center, on_delete=models.CASCADE )
groupmembers = models.ManyToManyField ( User, through='CategoryMembers' )
status = models.BooleanField ( default=True )
created_at = models.DateTimeField ( auto_now_add=True, null=True )
objects = AllManagers ()
def __str__(self) :
return self.description
# return "Centro: "+ (self.center.name)+" / "+(self.description)
class CategoryMembers ( models.Model ) :
id = models.UUIDField ( primary_key=True, default=uuid.uuid4, editable=False )
centercategory = models.ForeignKey ( CenterUserCategory, null=True, on_delete=models.CASCADE )
user = models.ForeignKey ( User, null=True, on_delete=models.CASCADE )
status = models.BooleanField(null=False,blank=True, default=True)
created_at = models.DateTimeField ( auto_now_add=True, null=True )