继承模型和外键

时间:2013-02-25 12:06:17

标签: python django

如果我还添加ApartamentLand对象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)

admin.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对象时才能工作。

1 个答案:

答案 0 :(得分:1)

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