diff options
-rw-r--r-- | app/books/migrations/0010_auto_20191223_0806.py | 37 | ||||
-rw-r--r-- | app/books/models.py | 15 |
2 files changed, 47 insertions, 5 deletions
diff --git a/app/books/migrations/0010_auto_20191223_0806.py b/app/books/migrations/0010_auto_20191223_0806.py new file mode 100644 index 0000000..d1f5065 --- /dev/null +++ b/app/books/migrations/0010_auto_20191223_0806.py @@ -0,0 +1,37 @@ +# Generated by Django 2.1.2 on 2019-12-23 08:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('books', '0009_book_afflink'), + ] + + operations = [ + migrations.AlterModelOptions( + name='bookhighlight', + options={'ordering': ('-page', '-date_added')}, + ), + migrations.RemoveField( + model_name='bookhighlight', + name='location', + ), + migrations.AddField( + model_name='bookhighlight', + name='body_html', + field=models.TextField(blank=True), + ), + migrations.AlterField( + model_name='bookhighlight', + name='date_added', + field=models.DateTimeField(auto_now_add=True), + ), + migrations.AlterField( + model_name='bookhighlight', + name='page', + field=models.PositiveSmallIntegerField(1), + preserve_default=False, + ), + ] diff --git a/app/books/models.py b/app/books/models.py index 00c0bdf..eb516a8 100644 --- a/app/books/models.py +++ b/app/books/models.py @@ -103,20 +103,25 @@ def post_save_events(sender, update_fields, created, instance, **kwargs): class BookHighlight(models.Model): book = models.ForeignKey(Book, on_delete=models.CASCADE) - page = models.PositiveSmallIntegerField(null=True) - location = models.CharField(max_length=200, blank=True, null=True) - date_added = models.DateTimeField() + page = models.PositiveSmallIntegerField() + date_added = models.DateTimeField(blank=True, auto_now_add=True) body_markdown = models.TextField() + body_html = models.TextField(blank=True) class Meta: - ordering = ('-date_added',) + ordering = ('-page', '-date_added') def __str__(self): return "%s%s" % (self.book.title, self.id) - def body_html(self): + def body_html_old(self): return markdown_to_html(self.body_markdown) + def save(self, *args, **kwargs): + 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" |