2
class One(models.Model):
    image = models.ImageField(upload_to="images")
    summary = models.TextField()

    def __unicode__(self):
        return self.summary


class Two(models.Model):
    image = models.ImageField(upload_to="images")
    title = models.CharField(max_length=50)

    def __unicode__(self):
        return self.title


class Three(models.Model):



  one = models.ForeignKey(One, related_name='one_home')
    two = models.ForeignKey(Two, related_name='two_home')

    def __unicode__(self):
        return self.tile

今私が欲しいのは、Django Admin で One と Two を Three のインラインとして表示することです。

どこでも検索しましたが、インライン表示は反対の関係に与えられます。Three の外部キーを持っている場合のように。私が望む逆ではありません。

4

1 に答える 1

0

かなり単純です:

あなたのモデルは「壊れて」います。3 つは 1 と 1 しか持てません。

One エンティティと Two エンティティの両方に対して 3 つのリストを持つことができます。

外部キーを逆にする場合は、それらがオンになっているモデルを変更します (両方とも @ Three を指しています)。

class OneToThreeInline(admin.StackedInline):
    fk_name = 'three'
    model = One

class TwoToThreeInline(admin.StackedInline):
    fk_name = 'three'
    model = Two
于 2013-03-11T14:04:12.820 に答える