is it possible to make a pivot table with the Django models?

0

Is it possible to create pivot tables in the database with the Django models ?, I need to create a table of that type to relate emails and telephones of a database in the tables of employees and clients

Is it possible to create these tables? How can I do it?

I know that I can do them directly in the database but the idea is that these tables are also versioned like the ones that Django creates with a model, it will be necessary just to put the model inside any other model.py class ?

Thanks for your help and comments!.

    
asked by Fernando A. León 02.03.2018 в 20:10
source

1 answer

0

If possible, it would be done in the following way. you declare a field in any of the 2 models, (employees or telephones). then you declare that the type of field is one of many to many, instantiating with the first argument the model with which it is related, and the field db_table would be, the name you want it to have in your database ..

Here I show you an example with a telephone.

class telefono(models.Model):
    empleado = models.ManyToManyField(Empleado, db_table="nombre_de_tabla_pivote")

for best reference link

    
answered by 02.03.2018 / 23:57
source