2013-02-25 156 views
-1

如何顯示,如果我加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, ] 

只有當我添加屬性對象這項工作。

+2

這裏有什麼問題?講清楚。 – arulmr 2013-02-25 12:07:43

+0

如果我添加'Apartament'和'Land'對象(現在它只在添加'Property'對象時才起作用),那麼如何創建StackInline? – user2096122 2013-02-25 12:10:05

回答

1

管理員(內聯)不是對稱的,您需要爲這些模型註冊管理員類,包括您需要的內聯。