from django.db import models from django.contrib.auth.models import User from amministratore.models import Amministratore class Azienda(models.Model): ''' questa classe definisce le società che gengono gestite dal programma. ogni utente può gestire una o più società. ''' nome = models.CharField(max_length=132,null=False,default="") partitaiva = models.CharField(max_length=11,null=False,default="") mail = models.CharField(max_length=256,null=False,default="") comm=models.CharField(max_length=256,null=False,default="") # email usata come mittente per le comunicazioni cambiopassword = models.BooleanField(null=False,default=0) class Meta: constraints = [ models.UniqueConstraint(fields=['nome','partitaiva'], name="unique-azienda") ] indexes = [ models.Index(fields=['partitaiva','nome']) ] def __str__(self): return f"{self.id}: {self.nome}" class Sede(models.Model): ''' 'ogni azienda ha almeno una sede'. ''' nome = models.CharField(max_length=132,null=False,default="") info = models.CharField(max_length=256,null=False,default="") azienda = models.ForeignKey(Azienda,on_delete=models.PROTECT) cambiopassword = models.BooleanField(null=False,default=0) def __str__(self): return f"{self.id}: {self.nome}" class AssegnazioneAzienda(models.Model): ''' questa tabella permette le associazioni tra società e Utente semmai, il problema è capire come associare la società all'utente registrato nella security ''' azienda = models.ForeignKey(Azienda,on_delete=models.PROTECT,null=True) amministratore = models.ForeignKey(Amministratore,on_delete=models.PROTECT,null=True) class AssegnazioneSede(models.Model): sede = models.ForeignKey(Sede,on_delete=models.PROTECT,null=True) azienda = models.ForeignKey(Azienda,on_delete=models.PROTECT,null=True) amministratore = models.ForeignKey(Amministratore,on_delete=models.PROTECT,null=True)