summaryrefslogtreecommitdiff
path: root/app/books/models.py
blob: 8c9fe9b8e22a427176ab427b1093399d2a9e3b9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from django.db import models
from django.template.defaultfilters import slugify

class Book(models.Model):
    title = models.CharField(max_length=200)
    author_name = models.CharField(max_length=200)
    slug = models.CharField(max_length=50)
    year_pub = models.CharField(max_length=4, blank=True, null=True)
    read_date = models.DateTimeField()
    isbn = models.CharField(max_length=100, blank=True, null=True)
    
    class Meta:
        ordering = ('-read_date',)
        
    def __str__(self):
        return self.title
    
    def save(self, *args, **kwargs):
        self.slug = slugify(self.title[:50])
        super(Book, self).save()

class BookHighlights(models.Model):
    book = models.ForeignKey(Book)
    page = models.PositiveSmallIntegerField(null=True)
    location = models.PositiveSmallIntegerField(null=True)
    date_added = models.DateTimeField()
    body_markdown = models.TextField()

    def __str__(self):
        return "%s%s" %(self.book.title, self.id)

class BookNotes(BookHighlights):
    pass