Ray's playground

 

The Django Admin Site(The Definitive Guild to Django)

admin.py
 1 from django.contrib import admin
 2 from mysite.books.models import Publisher, Author, Book
 3 
 4 class AuthorAdmin(admin.ModelAdmin):
 5     list_display = ('first_name''last_name''email')
 6     search_fields = ('first_name''last_name')
 7 
 8 class BookAdmin(admin.ModelAdmin):
 9     list_display = ('title''publisher''publication_date')
10     list_filter = ('publication_date',)
11     date_hierarchy = 'publication_date'
12 
13 admin.site.register(Publisher)
14 admin.site.register(Author, AuthorAdmin)
15 admin.site.register(Book, BookAdmin)
16 

 

models.py
 1 from django.db import models
 2 
 3 # Create your models here.
 4 class Publisher(models.Model):
 5     name = models.CharField(max_length=30)
 6     address = models.CharField(max_length=50)
 7     city = models.CharField(max_length=60)
 8     state_province = models.CharField(max_length=30)
 9     country = models.CharField(max_length=50)
10     website = models.URLField()
11 
12     def __unicode__(self):
13         return self.name
14 
15 class Author(models.Model):
16     first_name = models.CharField(max_length=30)
17     last_name = models.CharField(max_length=40)
18     email = models.EmailField(blank=True, verbose_name='e-mail')
19 
20     def __unicode__(self):
21         return u'%s %s' % (self.first_name, self.last_name)
22 
23 class Book(models.Model):
24     title = models.CharField(max_length=100)
25     authors = models.ManyToManyField(Author)
26     publisher = models.ForeignKey(Publisher)
27     publication_date = models.DateField(blank=True, null=True)
28 
29     def __unicode__(self):
30         return self.title
31 

 

 

posted on 2010-03-28 13:45  Ray Z  阅读(238)  评论(0编辑  收藏  举报

导航