2014-03-24 96 views
2

我有以下情形,其中有三個型號如下應顯示嵌套在Django管理。我使用Django 1.6版本,並應用在https://github.com/Soaa-/django-nested-inlines嵌套內聯在Django管理

然而豎起設置,它沒有露面與預期輸出。是否有任何其他解決方案,以實現在Django嵌套內聯。我是一個新手,這個框架。請指導我解決這個問題。

model.py

class Project(models.Model): 
    name = models.CharField(max_length=200) 
    code = models.IntegerField(default=0) 
    def __unicode__(self): 
     return self.name 

class Detail(models.Model): 
    project = models.ForeignKey(Project) 
    value = models.DecimalField(max_digits=5, decimal_places=2) 
    location = models.IntegerField(default=0) 

class Configuration(models.Model): 
    detail = models.OneToOneField(Detail) 
    content1 = models.IntegerField() 
    content2 = models.IntegerField() 

admin.py

from django.contrib import admin 
from nested_inlines.admin import NestedModelAdmin, NestedTabularInline, NestedStackedInline 

from myapp.models import Project, Detail, Configuration 

class ConfigInline(NestedStackedInline): 
    model = Configuration 
    extra = 1 

class DetailInline(NestedTabularInline): 
    model = Detail 
    inlines = [ConfigInline,] 
    extra = 1 

class ProjectAdmin(admin.ModelAdmin): 
    inlines = [DetailInline] 

admin.site.register(Project, ProjectAdmin) 

回答

0

我相信你忘了設置ProjectAdmin爲NestedModelAdmin:

admin.py

from django.contrib import admin 
from nested_inlines.admin import NestedModelAdmin, NestedTabularInline, NestedStackedInline 

from myapp.models import Project, Detail, Configuration 

class ConfigInline(NestedStackedInline): 
    model = Configuration 
    extra = 1 

class DetailInline(NestedTabularInline): 
    model = Detail 
    inlines = [ConfigInline,] 
    extra = 1 

class ProjectAdmin(NestedModelAdmin): 
    inlines = [DetailInline] 

admin.site.register(Project, ProjectAdmin)