I’m a newbie for django.
I’m trying to run a sample according to a book about django.
I’ve added “class Admin” to my model classes, however, in the django admin interface, I can only see the “Users”, “Groups” and “Sites”, none of my model classes appear.
There is no error or warning information, so I don’t know what happened and what shall I do next.
Any help?
from django.db import models
# Create your models here.
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()
def __str__(self):
return self.name
class Admin:
pass
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')
def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
class Admin:
pass
class Book(models.Model):
title=models.CharField(max_length=10)
authors=models.ManyToManyField(Author)
publisher=models.ForeignKey(Publisher)
publication_date = models.DateField()
def __str__(self):
return self.title
You need to do three things to be able to edit your models via admin site:
Create file ‘admin.py’ in your app directory with code (look https://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-objects):
In your urls.py add the following (look https://docs.djangoproject.com/en/dev/ref/contrib/admin/#hooking-adminsite-instances-into-your-urlconf):
Be sure, that your settings.py satisfy following (look https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overview):