Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: adding model to admin site

I dont know what i am doing wrong but i cant add model to my admin .

settings.py

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.admindocs',
'RM.cal',
'release',
'south',

)

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',
'django.middleware.gzip.GZipMiddleware',
'django_notify.middleware.NotificationsMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',

)

TEMPLATE_CONTEXT_PROCESSORS = (
        global_settings.TEMPLATE_CONTEXT_PROCESSORS +
        ('django.core.context_processors.request','django.contrib.messages.context_processors.messages',)

 )

admin.py

from cal.models import *
from django.contrib import admin
admin.site.register(Cos)

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'^RM/', include('RM.foo.urls')),
(r'^cal/', include('RM.cal.urls')),

# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
    {'document_root': 'C:/Users/sg0217297/Desktop/test/tkt_crmt/RM/media'}),

models.py its new field just for testing but i can add it to admin ;/

from django.db import models
from django.contrib import admin
class Cos(models.Model):
    name = models.CharField(max_length=400, blank= False , null = True)

    def __unicode__(self):
    return self.name

Any idea why ??

Thanks for help

E: Updated urls.py

like image 242
Silwest Avatar asked Jul 02 '26 14:07

Silwest


1 Answers

You need to define an app_label in your class, django only looks 1 level deep for models.py, so:

class YourModel(models.Model):
    # whatever

    class Meta:
        app_label = 'cal'

You can also import the 2nd level models within the init of the module above

like image 113
Hedde van der Heide Avatar answered Jul 04 '26 05:07

Hedde van der Heide