Уведомления

Группа в Telegram: @pythonsu

#1 Окт. 14, 2012 22:40:41

Radzhab
Зарегистрирован: 2012-07-05
Сообщения: 43
Репутация: +  0  -
Профиль   Отправить e-mail  

Какая разница между ForeignKey и ManyToManyField

в общем сабж

Офлайн

#2 Окт. 15, 2012 00:26:18

Chern
От: Киев
Зарегистрирован: 2010-09-15
Сообщения: 71
Репутация: +  3  -
Профиль   Отправить e-mail  

Какая разница между ForeignKey и ManyToManyField

ForeignKey представляет собой отношение “один ко многим”, ManyToManyField - “многие ко многим”



Офлайн

#3 Окт. 16, 2012 07:32:20

Radzhab
Зарегистрирован: 2012-07-05
Сообщения: 43
Репутация: +  0  -
Профиль   Отправить e-mail  

Какая разница между ForeignKey и ManyToManyField

хм.. кажись моветон делать многие ко многим) или я не прав?

Офлайн

#4 Окт. 16, 2012 09:44:58

FishHook
От:
Зарегистрирован: 2011-01-08
Сообщения: 8312
Репутация: +  568  -
Профиль   Отправить e-mail  

Какая разница между ForeignKey и ManyToManyField

Radzhab
хм.. кажись моветон делать многие ко многим) или я не прав?

Когда есть отношение многие-ко-многим Джанга создает кросс-таблицу и при запросах строит джойны через эту таблицу. Ты можешь предложить другой вариант реализации?



Офлайн

#5 Окт. 16, 2012 12:52:27

Radzhab
Зарегистрирован: 2012-07-05
Сообщения: 43
Репутация: +  0  -
Профиль   Отправить e-mail  

Какая разница между ForeignKey и ManyToManyField

Я не знал что джанга умеет такие вещи

Офлайн

#6 Окт. 16, 2012 14:14:43

FishHook
От:
Зарегистрирован: 2011-01-08
Сообщения: 8312
Репутация: +  568  -
Профиль   Отправить e-mail  

Какая разница между ForeignKey и ManyToManyField

Radzhab
Я не знал что джанга умеет такие вещи

class ManyToManyField(othermodel)
A many-to-many relationship. Requires a positional argument: the class to which the model is related. This works exactly the same as it does for ForeignKey, including all the options regarding recursive and lazy relationships.

Related objects can be added, removed, or created with the field's RelatedManager.

Database Representation
Behind the scenes, Django creates an intermediary join table to represent the many-to-many relationship. By default, this table name is generated using the name of the many-to-many field and the name of the table for the model that contains it. Since some databases don't support table names above a certain length, these table names will be automatically truncated to 64 characters and a uniqueness hash will be used. This means you might see table names like author_books_9cdf4; this is perfectly normal. You can manually provide the name of the join table using the db_table option.



Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version