1 from django.db import models
2 from forum.models import User
3 from forum.models import Question
4 from django.core.urlresolvers import reverse
5 from django.utils.http import urlquote as django_urlquote
6 from django.template.defaultfilters import slugify
8 class Book(models.Model):
12 user = models.ForeignKey(User)
13 title = models.CharField(max_length=255)
14 short_name = models.CharField(max_length=255)
15 author = models.CharField(max_length=255)
16 price = models.DecimalField(max_digits=6, decimal_places=2)
17 pages = models.SmallIntegerField()
18 published_at = models.DateTimeField()
19 publication = models.CharField(max_length=255)
20 cover_img = models.CharField(max_length=255)
21 tagnames = models.CharField(max_length=125)
22 added_at = models.DateTimeField()
23 last_edited_at = models.DateTimeField()
24 questions = models.ManyToManyField(Question, related_name='book', db_table='book_question')
26 def get_absolute_url(self):
27 return reverse('book', args=[django_urlquote(slugify(self.short_name))])
29 def __unicode__(self):
36 class BookAuthorInfo(models.Model):
38 Model for book author info
40 user = models.ForeignKey(User)
41 book = models.ForeignKey(Book)
42 blog_url = models.CharField(max_length=255)
43 added_at = models.DateTimeField()
44 last_edited_at = models.DateTimeField()
48 db_table = u'book_author_info'
50 class BookAuthorRss(models.Model):
52 Model for book author blog rss
54 user = models.ForeignKey(User)
55 book = models.ForeignKey(Book)
56 title = models.CharField(max_length=255)
57 url = models.CharField(max_length=255)
58 rss_created_at = models.DateTimeField()
59 added_at = models.DateTimeField()
63 db_table = u'book_author_rss'