python - How can I set a Foreign Key to the default through in Django? -
i want set foreign key many many relationship without having specify through field or (specify without affecting existing logic).
monitor.py
class quotemonitor(g.usermodel): quote_services = m. onetoonefield(g.quoteservice)
quote.py
class quote(g.usermodel): name = m.charfield(max_length=512, default='new quote') services = m.manytomanyfield(g.service, blank=true) class service(g.usermodel): name = m.charfield(max_length=512, default='new service')
i can't right because g.quoteservice model doesn't exist. table automatically created django many-to-many field.
is possible?
edit:
this question provides similar answer.
you can create unmanaged model many-to-many relationship django automatically creates.
class quoteservice(models.model): quote = m.foreignkey(g.quote) service = m.foreignkey(g.service) class meta: db_table = 'table-name-goes-here' managed = false
then can create model references m2m relationship via foreignkey or 1-1 field:
class quotemonitor(g.usermodel): quote_service = m.onetoonefield(g.quoteservice)
note: should create quotemonitor in 2nd migration, after initial models have been created.
Comments
Post a Comment