A
A
Alexander2017-01-22 21:56:22
Django
Alexander, 2017-01-22 21:56:22

How to make such a connection?

There are ordinary users ( performers ). And there are projects , and projects have modules , and a project has performers . Several performers can participate in one project. And one project can have several modules. But the modules have one executor.
How can you make a connection like this?

status_choice = (
    (0, 'Not ready'),
    (1, 'Ready')
)


class Project(models.Model):
    name = models.CharField(max_length=200)
    price = models.IntegerField()
    user = models.ManyToManyField(User, verbose_name='Executors')
    status = models.IntegerField(default=0, choices=status_choice)
    start_date = models.DateTimeField(blank=True, null=True)
    end_date = models.DateTimeField(blank=True, null=True)

    def __str__(self):
        return self.name


class Module(models.Model):
    name = models.CharField(max_length=200)
    project = models.ForeignKey(Project, on_delete=models.CASCADE)
    user = models.ForeignKey(Project.user, verbose_name='Executor')
    start_date = models.DateTimeField(blank=True, null=True)
    end_date = models.DateTimeField(blank=True, null=True)
    status = models.IntegerField(default=0, choices=status_choice)

    def __str__(self):
        return self.name

this code is just indicative, here: user = models.ForeignKey(Project.user, verbose_name='Executors') django doesn't understand what I want

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zelsky, 2017-01-22
@zelsky

Take ContentType Product and shamanize with the User field.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question