How do I tell Django to not create a table for an M2M related field?

前端 未结 3 1753
粉色の甜心
粉色の甜心 2021-01-16 12:17

I\'m using this little jewel of a Django code snippet to edit a ManyToManyField from both directions:

class ManyToManyField_NoSyncdb(models.ManyToManyField):         


        
3条回答
  •  梦谈多话
    2021-01-16 12:42

    The "managed" meta option for models might be helpful. From http://docs.djangoproject.com/en/1.2/ref/models/options/#managed

    If a model with managed=False contains a ManyToManyField that points to another unmanaged model, then the intermediate table for the many-to-many join will also not be created. However, the intermediary table between one managed and one unmanaged model will be created.

    If you need to change this default behavior, create the intermediary table as an explicit model (with managed set as needed) and use the ManyToManyField.through attribute to make the relation use your custom model.

提交回复
热议问题