rakkapy/books/models.py

26 lines
775 B
Python
Raw Permalink Normal View History

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):
2021-10-29 05:05:42 +11:00
chaps=Chapter.objects.filter(book=self).order_by('added')
return chaps[0].added if chaps else None
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)