I would like to know how to do so that in my “Association” model, the “client” field displays the models “ClientIntermediaire, ClientDemiGros,ClientDetaillant” with relationship “ForeignKey”.
class Client(models.Model):
name = models.CharField(blank=False, null=False, max_length=15)
first_name = models.CharField(blank=False, null=False, max_length=30)
phone_perso = PhoneNumberField(unique=True, null=False, blank=False)
email = models.EmailField(blank=True, null=True, default=None, unique=True)
city = models.CharField(null=False, blank=False, max_length=30)
gps_longitude = models.DecimalField(max_digits=8, decimal_places=3, null=True, blank=True)
gps_latitude = models.DecimalField(max_digits=8, decimal_places=3, null=True, blank=True)
created_by= models.ForeignKey(User, on_delete=models.PROTECT)
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.first_name + ' ' + self.name
class Meta:
abstract = True
# Model of Client (Type = Intermediaire)
class ClientIntermediaire(Client):
# Different statuses that a "Intermediaire" type customer can take
STATUS_CLIENT = (('actif', 'Actif'), ('inactif', 'Inactif'), ('suspendu', 'Suspendu'))
type_client = models.CharField(default="intermediaire", blank=False, null=False, editable=False, max_length=13)
status = FSMField(default=STATUS_CLIENT[0])
class ClientDemiGros(Client):
# Different statuses that a "Demi-gros" type customer can take
STATUS_CLIENT = (('actif', 'Actif'), ('inactif', 'Inactif'),('suspendu', 'Suspendu'))
type_client = models.CharField(default="demi-gros", max_length=13, blank=False, null=False, editable=False)
intermediate = models.ForeignKey(ClientIntermediaire, on_delete=models.PROTECT, blank=True, null=False)
status = FSMField(default=STATUS_CLIENT[0])
# Model to associate a phoneNumber to a Client
class Association(models.Model):
number = models.ForeignKey(PhoneNumber, on_delete=models.PROTECT)
client = models.ForeignKey((ClientIntermediaire, ClientDemiGros), on_delete=models.PROTECT)