A
A
Andrey2015-11-10 19:02:08
Django
Andrey, 2015-11-10 19:02:08

Work schedule for companies, how best to link a table?

Hello!
There is a Company model with information about the company.
You need to attach the work schedule to the companies on the site, as in the photo:
6f820b5b2db24827871cb8ee58443fde.png
I understand that you need to add an additional Schedule table (with fields: day of the week, start date, end date and breaks).
What is the best way to bind Schedule to Company via manytomany or foreign key?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Foo Bar, 2015-11-10
@atomheart

Here you need to proceed from the task (it is not completely clear on the issue).
If you have one or more schedules for one company, then through Foreign Key. In this case, all companies will have their own copies of schedules.
And if you need to make it so that several companies should have a common schedule, then ... also Foreign Key in the company model :)
ManyToMany is a many-to-many relationship, i.e. when “you don’t understand anything at all” and any company can have either its own schedule, or someone else’s, or both.
... if I understand the question correctly, of course)

O
Oscar Django, 2015-11-11
@winordie

The main disadvantage of using m2m in this situation is that changing the schedule for one company, it will change for others associated with this record.
Here you need to think about the essence of objects. The schedule is not self-sufficient, it depends entirely on the company.
I think it would not even be criminal to make a Schedule model with 14 fields of the day_week_start/end type.
Or, as you wanted, the Schedule table with the fields day_of the week, company, start, end. At the same time, with control over the uniqueness of the day_of the week <==> company.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question