继承模式和外键
问题描述:
如何显示,如果我加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)
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, ]
只有当我添加属性对象这项工作。
答
管理员(内联)不是对称的,您需要为这些模型注册管理员类,包括您需要的内联。
这里有什么问题?讲清楚。 – arulmr 2013-02-25 12:07:43
如果我添加'Apartament'和'Land'对象(现在它只在添加'Property'对象时才起作用),那么如何创建StackInline? – user2096122 2013-02-25 12:10:05