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