Django Book: The Django Administration Site

2 views
Skip to first unread message

Mikey3D

unread,
Jan 6, 2008, 2:10:43 PM1/6/08
to Django users
Hi, I'm reading thoroughly the new django book and on page 86, the
figure 6-2, why didn't the Django Administration Site showing Ch6
except only Auth and Sites showing? I have trying all morning to
figure it out but can't.

Here are my files:

# Django settings for mysite project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_...@domain.com'),
)

MANAGERS = ADMINS

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'databook.db'
DATABASE_USER = ''
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_PORT = ''

TIME_ZONE = 'America/New_York'

LANGUAGE_CODE = 'en-us'

SITE_ID = 1

USE_I18N = True

MEDIA_ROOT = ''

MEDIA_URL = ''

ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'm+e&w_07)j!y_$sw%)5@dpm9(d$mm3a88oeyx82mf==m-6ud7^'

# List of callables that know how to import templates from various
sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
# 'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

TEMPLATE_DIRS = ('C:/djcode/mysite/templates',
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'mysite.books',
)
---------------------------------------------------------------------------------------------------

urls.py

from django.conf.urls.defaults import *
from mysite.views import current_datetime, hours_ahead

urlpatterns = patterns('',
(r'^time/$', current_datetime),
(r'^time/plus/(\d{1,2})/$', hours_ahead),

# Uncomment this for admin:
(r'^admin/', include('django.contrib.admin.urls')),
)
------------------------------------------------------------------------------------------------------

models.py

from django.db import models

class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()

class Admin: pass

def __str__(self):
return self.name

class Meta:
ordering = ["name"]

class Author(models.Model):
salutation = models.CharField(max_length=10)
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
headshot = models.ImageField(upload_to='/tmp')

class Admin: pass

def __str__(self):
return '%s %s' % (self.first_name, self.last_name)

class Book(models.Model):
title = models.CharField(max_length=100)
author = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()

class Admin: pass

def __str__(self):
return self.title

Thanks, Mikey3D

PS: Windows 98

goober

unread,
Jan 6, 2008, 3:44:26 PM1/6/08
to Django users
Mikey3D,

I believe you need to seed the database by typing python manage sql
<model name> or type python manage sqlall. The you need to type python
manage syncdb db again.

Cheeers.

Did you run python manage syncdb?
Did you run python manage sqlall?

On Jan 6, 2:10 pm, Mikey3D <snapmi...@hotmail.com> wrote:
> Hi, I'm reading thoroughly the new django book and on page 86, the
> figure 6-2, why didn't the Django Administration Site showing Ch6
> except only Auth and Sites showing? I have trying all morning to
> figure it out but can't.
>
> Here are my files:
>
> # Django settings for mysite project.
>
> DEBUG = True
> TEMPLATE_DEBUG = DEBUG
>
> ADMINS = (
> # ('Your Name', 'your_em...@domain.com'),

Mikey3D

unread,
Jan 6, 2008, 5:34:57 PM1/6/08
to Django users
Hi goober,

I have done your suggestions before or I won't be able to create a
superuser, right? I could login and there is no Ch6 but only Auth and
Sites in Admin Interface. So I try again your suggestions:

In command:

python manage.py sql books "OR" python manage.py sqlall books > the
same difference.

Then python manage.py syncdb

Then python manage.py runserver

There is no Ch6.

Thanks, Mikey3D

Ramiro Morales

unread,
Jan 6, 2008, 6:33:55 PM1/6/08
to django...@googlegroups.com
On Jan 6, 2008 5:10 PM, Mikey3D <snap...@hotmail.com> wrote:
> [...]

> from django.db import models
>
> class Publisher(models.Model):
> name = models.CharField(max_length=30)
> address = models.CharField(max_length=50)
> city = models.CharField(max_length=60)
> state_province = models.CharField(max_length=30)
> country = models.CharField(max_length=50)
> website = models.URLField()
>
> class Admin: pass
>
> def __str__(self):
> return self.name
>
> class Meta:
> ordering = ["name"]
>

So, is this a copy/paste error or you are really defining what
should be model inner classes (Admin, Meta) as top-level classes?.

If he latter, that could be a posible reason for he behaviour you are
seeing. Rewrite them
like:

class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()

class Admin: pass

def __str__(self):
return self.name

class Meta:
ordering = ["name"]


(same thing for the model methods)

Regards,

--
Ramiro Morales

elgringo

unread,
Jan 6, 2008, 7:10:03 PM1/6/08
to Django users
Like Ramiro says. It's an indentation issue.

Your nested class Admin: pass statement needs to be one and only one
level of indentation below the top class declaration for each class
that you're defining:

class Publisher(model.Model):
...
class Admin: pass

class Foo(model.Model):
...
class Admin: pass

Good luck

On Jan 6, 3:33 pm, "Ramiro Morales" <cra...@gmail.com> wrote:

Mikey3D

unread,
Jan 6, 2008, 9:40:21 PM1/6/08
to Django users
Hi Elgringo,

Thank you so much it works. :-) One question, why is that I have Auth
and Sites are showing up when my "class Admin: pass" were wrong way of
coding still works?

Hi Ramiro, I wasn't sure what you mean by copy/paste error and inner
class but Elgringo clearly what you were saying. Thank you. You know I
can't copy/paste the text from new django book. I look over again on
page 84 it was my mistakes. I using ActiveState Python IDE editor when
I press enter twice it was way off.

Cheer, Mikey3D

iamelgringo

unread,
Jan 7, 2008, 12:34:54 PM1/7/08
to Django users
The book is online if you want to copy/paste code:
http://www.djangobook.com/en/1.0/chapter06/

Good luck and no problem.

Ramiro Morales

unread,
Jan 7, 2008, 1:24:08 PM1/7/08
to django...@googlegroups.com
On Jan 7, 2008 12:40 AM, Mikey3D <snap...@hotmail.com> wrote:
>
> Thank you so much it works. :-) One question, why is that I have Auth
> and Sites are showing up when my "class Admin: pass" were wrong way of
> coding still works?
>

Because these are different apps? and they have their Admin inner classes
correctly defined in their own models.py files.

> Thank you. You know I can't copy/paste the text from new django book.

I meant copy/paste from your code to the e-mail.

Regards,

--
Ramiro Morales

Reply all
Reply to author
Forward
0 new messages