]> git.openstreetmap.org Git - osqa.git/blob - forum_modules/books/models.py
I don't think this was an issue but it was annoying me. I made it so the the text...
[osqa.git] / forum_modules / books / models.py
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
7
8 class Book(models.Model):
9     """
10     Model for book info
11     """
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')
25
26     def get_absolute_url(self):
27         return reverse('book', args=[django_urlquote(slugify(self.short_name))])
28
29     def __unicode__(self):
30         return self.title
31         
32     class Meta:
33         app_label = 'forum'
34         db_table = u'book'
35
36 class BookAuthorInfo(models.Model):
37     """
38     Model for book author info
39     """
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()
45
46     class Meta:
47         app_label = 'forum'
48         db_table = u'book_author_info'
49
50 class BookAuthorRss(models.Model):
51     """
52     Model for book author blog rss
53     """
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()
60
61     class Meta:
62         app_label = 'forum'
63         db_table = u'book_author_rss'