From 6288785513e1d4590e14c3abfa70c700b6398c64 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Mon, 23 Dec 2019 10:01:21 -0500 Subject: fixed book hilights to auto add book if not filled in --- app/books/models.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'app/books') diff --git a/app/books/models.py b/app/books/models.py index 004ed8c..8e8b485 100644 --- a/app/books/models.py +++ b/app/books/models.py @@ -109,20 +109,20 @@ class BookHighlight(models.Model): body_html = models.TextField(blank=True) class Meta: - ordering = ('-page', '-date_added') + ordering = ('-date_added', '-page',) + get_latest_by = 'date_added' def __str__(self): - return "%s%s" % (self.book.title, self.id) - - def body_html_old(self): - return markdown_to_html(self.body_markdown) + return "%s - %s" % (self.book.title, self.id) def save(self, *args, **kwargs): + if not self.pk: + if self.book_id is None: + self.book = BookHighlight.objects.latest().book self.body_html = markdown_to_html(self.body_markdown) - if not self.book: - self.book = BookHighlight.objects.latest().book super(BookHighlight, self).save() + class BookSitemap(Sitemap): changefreq = "never" priority = 0.7 -- cgit v1.2.3-70-g09d2