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

前端 未结 3 1648
粉色の甜心
粉色の甜心 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:47

    Let me post the new solution in Django's ticket #897, which mention by Etienne too. It work well in Django 1.2.

    class Test1(models.Model):
        tests2 = models.ManyToManyField('Test2', blank=True)
    
    class Test2(models.Model):
        tests1 = models.ManyToManyField(Test1, through=Test1.tests2.through, blank=True)
    

提交回复
热议问题