V
V
Vladimir Mukhin2020-01-10 20:48:33
css
Vladimir Mukhin, 2020-01-10 20:48:33

How to properly make relationships between models in Django?

class Employee(models.Model):
    name = models.CharField('Имя сотрудника', max_length=50, blank=True)

class Post(models.Model):
    name = models.CharField('Название поста', max_length=50, blank=True)

class Duty(models.Model):
    date = models.DateField('Дата дежурства', auto_now=False, auto_now_add=False)

How should the Duty model be correctly supplemented so that an arbitrary number of pairs of Post values ​​can be attributed to it: Employee
How to do this correctly, I just can’t think of?
The practical meaning is this:
On the page you want to place a form that creates a Duty object, with several pairs of Post values: Employee

Answer the question

In order to leave comments, you need to log in

3 answer(s)
ⓒⓢⓢ, 2019-03-22
@saplas

when he started to set the background th

th to thead? ...then and the gradient on thead hang

D
Dr. Bacon, 2020-01-10
@bacon

Add an "intermediate" model with three ForeignKeys to these models.

N
noxplex, 2020-01-13
@noxplex

class Duty(models.Model):
    date = models.DateField('Дата дежурства', auto_now=False, auto_now_add=False)
    employee = models.ForeignKey(Employee)
    post = models.ForeignKey(Post)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question