M
M
Mimobike2021-09-02 22:30:50
Django
Mimobike, 2021-09-02 22:30:50

How to create objects while creating another object?

Hello, do you have models?

class Day(models.Model):
    date = models.DateField()


class ReservedTable(models.Model):
    is_reserved = models.BooleanField()
    table = models.ForeignKey(Table, on_delete=models.CASCADE)
    day = models.ForeignKey(Day, on_delete=models.CASCADE)

how is it possible, when creating a Day, to run through all Tables, create a ReservedTable and associate it with the same Day?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2021-09-02
@Mimobike

post_save signal on Day.
And there, already inside, go over the table and assign the day to the ReservedTable, which will fly to you in instance ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question