0
I have a User model, which are the users with access to the system, only that each user has to be registered in a work sector, I would like to filter and send via API the list of sectors that have registered employees. Ex: I have 3 sectors registered Setor_a, Setor_b and Setor_c, but, only have Users registered in Setor_a and Setor_c, then the views should return only JSON with these two sectors. Details: These objects are not nested.
class User(AbstractBaseUser, PermissionsMixin):
username = models.CharField('Nome', max_length=255, db_index=True)
email = models.EmailField(max_length=255, unique=True, db_index=True)
nivel = models.CharField(max_length=100, null=True, blank=True)
setor = models.CharField(max_length=100, null=True, blank=True)
cpf = models.CharField(max_length=11, blank=True, null=True, unique=True)
class Setor(models.Model):
setor = models.CharField(max_length=100)
chefe = models.CharField(max_length=100)
contato = models.CharField(max_length=100, blank=True, null=True,)
Preferably the view is of the Modelviewset type, thanks in advance.