How to Use Multiple Models in a Foreign Key Relationship?

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)

Please do not post images of code here. They’re hard to read, and can’t be searched or quoted for commenting.
Copy/paste the code into the body of your message, surrounded by lines of three backtick - ` characters to maintain formatting. That means you’ll have a line of ```, then your code, then another line of ```.

From what I can read, it looks like you’ve got an error in your Association model - your definition of the client field is wrong. Also, you’re not showing your Client model here. Is it an abstract class or a concrete class?

Also, please clarify what you mean by your question. Are you asking how to create a template to show those fields when you’re displaying an instance of Association?

Sorry, I corrected the post.
In fact I want to be able to add the instances of the 02 models (ClientIntermediaire, ClientDemiGros) in the “Client” field in the “Association” model.

It doesn’t work that way. The client field is a ForeignKey to a related model. It is a reference to a model, it does not “contain” those instances. If you want two references (each to a different model), then you need two ForeignKey fields.

I don’t know what the actual relationship is supposed to be among these models, so I can’t provide any specific advice, but I suggest you re-evaluate how you have your models defined and what you’re trying to achieve by these relationships.

Okay, I understand. i will try to change my models.