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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -