-1

Apartament如果我添加和Land对象也Contact形成和形成,如何显示Photo

class Property(models.Model):
    title = models.CharField(max_length=255)
    slug = models.SlugField()
    desc = models.TextField()

class Apartament(Property):
    bedrooms = models.IntegerField()
    levels = models.IntegerField()
    something = models.CharField(max_length=255)

class Land(Property):
    something = models.CharField(max_length=255)

class Contact(models.Model):
    name = models.CharField(max_length=100)
    phone = models.CharField(max_length=20)
    property = models.ForeignKey(Property)

class Photo(models.Model):
    photo = models.ImageField(upload_to='images')
    property = models.ForeignKey(Property)

管理员.py:

class PhotoInline(admin.StackedInline):
    model = Photo
    can_delete = True

class ContactInline(admin.StackedInline):
    model = Contact
    can_delete = True

class PropertyAdmin(admin.ModelAdmin):
    inlines = [PhotoInline, ContactInline, ]

仅当我添加 Property 对象时才有效。

4

1 回答 1

1

Admin(inline)s 不是对称的,您还需要为这些模型注册管理类,包括您需要的内联。

于 2013-02-25T12:12:44.870 回答