模型没有出现在 django admin 中 [英] model not showing up in django admin

查看:27
本文介绍了模型没有出现在 django admin 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为自己的基金创建了几个 django 应用程序和东西,到目前为止一切正常.

I have ceated several django apps and stuffs for my own fund and so far everything has been working fine.

现在我刚刚创建了新项目(django 1.2.1)并且从一开始就遇到了麻烦.

Now I just created new project (django 1.2.1) and have run into trouble from 1st moments.

我创建了新应用 - 游戏和新模型游戏.我创建了 admin.py 并将相关的东西放入其中.跑了syncdb并去检查管理员.模型没有出现在那里.

I created new app - game and new model Game. I created admin.py and put related stuff into it. Ran syncdb and went to check into admin. Model did not show up there.

我继续检查并仔细检查并阅读了以前的类似线程:注册模型不会显示在管理员中Django 应用程序未显示在管理界面中

I proceeded to check and doublecheck and read through previous similar threads: Registered models do not show up in admin Django App Not Showing up in Admin Interface

但据我所知,他们也没有帮助我.也许其他人可以为我指出这一点.

But as far as I can tell, they don't help me either. Perhaps someone else can point this out for me.

游戏应用中的models.py:

models.py in game app:

# -*- coding: utf-8 -*-
from django.db import models

class Game(models.Model):
      type = models.IntegerField(blank=False, null=False, default=1)
      teamone = models.CharField(max_length=100, blank=False, null=False)
      teamtwo = models.CharField(max_length=100, blank=False, null=False)
      gametime = models.DateTimeField(blank=False, null=False)

游戏应用中的admin.py:

admin.py in game app:

# -*- coding: utf-8 -*-
from jalka.game.models import Game
from django.contrib import admin

class GameAdmin(admin.ModelAdmin):
      list_display    = ['type', 'teamone', 'teamtwo', 'gametime']

admin.site.register(Game, GameAdmin)

项目设置.py:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'jalka.urls'

TEMPLATE_DIRS = (
      "/home/projects/jalka/templates/"
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'game',
)

urls.py:

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
      # Example:
      # (r'^jalka/', include('jalka.foo.urls')),
      (r'^admin/', include(admin.site.urls)),
)

推荐答案

报告的问题可能是因为您跳过了为管理站点注册模型.这可以做到,在你的应用下创建一个 admin.py 文件,并在那里注册模型:

The problem reported can be because you skipped registering the models for the admin site. This can be done, creating an admin.py file under your app, and there registering the models with:

from django.contrib import admin
from .models import MyModel

admin.site.register(MyModel)

这篇关于模型没有出现在 django admin 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆