2016-02-15 158 views
0

我是Django的新手,我有這樣的簡單模型。Django在管理中不顯示模型

from django.db import models 
from django.contrib.auth.models import User 

class Todo(models.Model): 
    owner = models.ForeignKey(User) 
    description = models.CharField(max_length=30) 
    done = models.BooleanField() 
    updated = models.DateTimeField(auto_now_add=True) 

class News(models.Model): 
    title = models.TextField(max_length=400000) 
    description = models.TextField(max_length=400000) 
    created  = models.DateTimeField(editable=False) 
    modified = models.DateTimeField() 

    def save(self, *args, **kwargs): 
     ''' On save, update timestamps ''' 
     if not self.id: 
      self.created = timezone.now() 
     self.modified = timezone.now() 
     return super(User, self).save(*args, **kwargs) 

在URL,

from django.conf.urls import patterns, include, url 
from todo import views 
from rest_framework import viewsets, routers 
from django.contrib import admin 

router = routers.DefaultRouter() 

admin.autodiscover() 

urlpatterns = patterns('', 

    url(r'^admin/', admin.site.urls), 
    url(r'^', include(router.urls)), 
) 

我檢查計算器和他們說的自動發現應該被刪除。但如果我刪除,我看到這樣。我該怎麼做,以便我的模型在管理中顯示?

enter image description here

回答

1

在admin.py文件做到這一點

from django.contrib import admin 
from .models import Todo, News 

# Register your models here. 

admin.site.register(Todo) 
admin.site.register(News) 

您的應用可能不是INSTALLED_APPS註冊,如果它劑量'找到你的應用程序失敗,沒有發生錯誤

+0

你們搖滾。謝謝 –