My app/models.py
from Milestone 2:
from django.db import models
from django.contrib import admin
from liu.models import Course
from django.contrib.auth.models import User
# Create your models here.
class Book(models.Model):
isbn = models.CharField(max_length='20')
title = models.CharField(max_length='80')
authors = models.CharField(max_length='120')
publisher = models.CharField(max_length='80')
edition = models.CharField(max_length='20')
course = models.ManyToManyField(Course)
def __unicode__(self):
return '%s %s' % (self.isbn, self.title)
class BookAdmin(admin.ModelAdmin):
list_display = ['isbn', 'title', 'authors', 'publisher', 'edition']
search_fields = ['isbn', 'title', 'authors', 'publisher']
class Listing(models.Model):
book = models.ForeignKey(Book)
user = models.ForeignKey(User)
sell = models.BooleanField()
price = models.FloatField(blank=True, null=True)
def __unicode__(self):
return '%s %s %s' % (self.user,
'selling' if self.sell else 'buying',
self.book)
class ListingAdmin(admin.ModelAdmin):
list_display = ['book', 'user', 'sell', 'price']
list_filter = ['sell']
search_fields = ['book', 'user']
admin.site.register(Book, BookAdmin)
admin.site.register(Listing, ListingAdmin)
comments
powered by Disqus
©2012 Christopher League · some rights reserved · CC by-sa