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 对象时才有效。