CREATE list from two Fields in Django

I don’t know if there a possibilty to create a field model from two fields different model. for example, I have this two models :

class BaseOil(models.Model):
BaseoilName = models.CharField(max_length=150)

class Additif(models.Model):
AdditifName = models.CharField(max_length=150)

BaseoilName contain some composant and AdditifName contain some compostant too and different of BaseoilName, so I want to create a list from this two compostant in one list in another model exactly in Compostants field, like:

class Composants(models.Model):
    Composant = models.ForeignKey(I want to merge both BaseOil and Additif names here )
    Comp_Qte = models.floatsField()

I tried some tutorial from Youtube and from Django Project document, but I didn’t succeed to have my objective.

so thank you for helping to get it, and I will be very thankfull

Hello @kingman29
You have several options to achieve what you’re tying to.
One of the options would be to create a custom function inside the “Composants” model, where you get the names of “BaseOil” and “AdditIf” and put it inside “Composant” field. Using this option you’d need to change this last field from ForeingKey to CharField, so you also would lost the relationship between the models.
I think you have 2 options:
*To use another ForeingKey field within “Composant” model (in case you only have 1 BaseOil and 1 AdditIf for every Composant) like this:

class Composants(models.Model):
    BaseOil = models.ForeignKey(models.BaseOil)
    AdditIf = models.ForeignKey(models.AdditIf)
    Comp_Qte = models.floatsField()

*Or use a ManyToMany field and merge the BaseOil and AdditIf models into one, like this:

# Merging BaseOil and AdditIf into one model
class Component(models.Model):
ComponentName = models.CharField(max_length=150)

class Composants(models.Model):
    Component = models.ManyToManyField(Component)
    Comp_Qte = models.floatsField()

If this last option seems accurated, you can look more information here: Many-to-many relationships | Django documentation | Django
I’m not really sure about this, but I’d recommend you to rethink the normalization of your databases, as I’m not sure what you’d want to have 2 differents models with the same information inside, and then merging them into 1 field as a ForeignKey in another model.

thank you
I tried the first option, it work for me