rakkapy/books/models.py

25 lines
742 B
Python

from django.db import models
from datetime import date
# Create your models here.
class Book(models.Model):
title=models.CharField(max_length=200)
url=models.CharField(max_length=100)
added=models.DateField(auto_now_add=True)
@property
def last_updated(self):
return Chapter.objects.filter(book=self).order_by('added')[0].added
def __str__(self):
return self.title
class Chapter(models.Model):
book=models.ForeignKey(Book, on_delete=models.CASCADE)
number=models.IntegerField(default=0)
title=models.CharField(max_length=200, blank=True, null=True)
contents=models.TextField(blank=True, null=True)
added=models.DateField(auto_now_add=True)
def __str__(self):
return self.title or self.book.title+' '+str(self.number)