Python 继承模型与外键
如果我同时添加Python 继承模型与外键,python,django,Python,Django,如果我同时添加公寓和土地对象联系人表单和照片表单,如何显示 class Property(models.Model): title = models.CharField(max_length=255) slug = models.SlugField() desc = models.TextField() class Apartament(Property): bedrooms = models.IntegerField() levels = models
公寓
和土地
对象联系人
表单和照片
表单,如何显示
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, ]
只有在我添加属性对象的情况下,这才有效。管理(内联)不是对称的,您还需要为这些模型注册管理类,包括您需要的内联线。这里的问题是什么?明确说明。如果我添加
公寓
和土地
对象,如何创建StackInline(目前仅当我添加属性
对象时才有效)