Django admin inline display but foreign key has opposite relation

前端 未结 1 1646
小鲜肉
小鲜肉 2021-01-15 05:56
class One(models.Model):
    image = models.ImageField(upload_to=\"images\")
    summary = models.TextField()

    def __unicode__(self):
        return self.summary         


        
相关标签:
1条回答
  • 2021-01-15 06:19

    rather simple:

    Your model is "broken", three can have only 1 One and 1 Two.

    you can have a list of three for both One an Two entities.

    If you reverse the foreign keys, change the models they are on (both pointing @ Three)

    class OneToThreeInline(admin.StackedInline):
        fk_name = 'three'
        model = One
    
    class TwoToThreeInline(admin.StackedInline):
        fk_name = 'three'
        model = Two
    
    0 讨论(0)
提交回复
热议问题