diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/posts/admin.py | 31 | ||||
-rw-r--r-- | app/posts/migrations/0022_trip_post_trip.py | 37 | ||||
-rw-r--r-- | app/posts/models.py | 25 |
3 files changed, 91 insertions, 2 deletions
diff --git a/app/posts/admin.py b/app/posts/admin.py index 22c7955..f9d679b 100644 --- a/app/posts/admin.py +++ b/app/posts/admin.py @@ -4,7 +4,7 @@ from django.contrib.gis.admin import OSMGeoAdmin from django.contrib.contenttypes.admin import GenericStackedInline from utils.widgets import AdminImageWidget, LGEntryForm -from .models import Post +from .models import Post, Trip from media.models import LuxImage from utils.util import get_latlon @@ -97,4 +97,31 @@ class PostAdmin(OSMGeoAdmin): } - +@admin.register(Trip) +class TripAdmin(OSMGeoAdmin): + form = LGEntryForm + list_display = ('title', ) + prepopulated_fields = {'slug': ('title',)} + search_fields = ('title',) + fieldsets = ( + ('Region', { + 'fields': ( + 'title', + 'subtitle', + 'body_markdown', + 'slug', + 'date_started', + 'date_ended', + 'featured_image' + ), + 'classes': ( + 'show', + 'extrapretty' + ) + }), + ) + class Media: + js = ('image-loader.js', 'next-prev-links.js') + css = { + "all": ("my_styles.css",) + } diff --git a/app/posts/migrations/0022_trip_post_trip.py b/app/posts/migrations/0022_trip_post_trip.py new file mode 100644 index 0000000..6f01b0c --- /dev/null +++ b/app/posts/migrations/0022_trip_post_trip.py @@ -0,0 +1,37 @@ +# Generated by Django 4.2.1 on 2023-05-23 15:25 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('media', '0008_auto_20201202_1155'), + ('posts', '0021_alter_post_post_type'), + ] + + operations = [ + migrations.CreateModel( + name='Trip', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=300)), + ('subtitle', models.CharField(blank=True, max_length=200)), + ('slug', models.SlugField()), + ('body_markdown', models.TextField()), + ('body_html', models.TextField(blank=True)), + ('date_started', models.DateField()), + ('date_ended', models.DateField()), + ('featured_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='media.luximage')), + ], + options={ + 'ordering': ('-date_started',), + }, + ), + migrations.AddField( + model_name='post', + name='trip', + field=models.ManyToManyField(blank=True, null=True, to='posts.trip'), + ), + ] diff --git a/app/posts/models.py b/app/posts/models.py index 1510820..5fa8627 100644 --- a/app/posts/models.py +++ b/app/posts/models.py @@ -38,6 +38,30 @@ def get_upload_path(self, filename): return "images/post-images/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) +class Trip(models.Model): + title = models.CharField(max_length=300) + subtitle = models.CharField(max_length=200, blank=True) + slug = models.SlugField() + body_markdown = models.TextField() + body_html = models.TextField(blank=True) + date_started = models.DateField() + date_ended = models.DateField() + featured_image = models.ForeignKey(LuxImage, on_delete=models.SET_NULL, null=True, blank=True) + + def __str_(self): + return self.title + + class Meta: + ordering = ('-date_started',) + + def save(self, *args, **kwargs): + created = self.pk is None + if not created: + md = render_images(self.body_markdown) + self.body_html = markdown_to_html(md) + super(Track, self).save(*args, **kwargs) + + class PostType(models.IntegerChoices): RANGE = 0, ('range') REVIEW = 1, ('review') @@ -87,6 +111,7 @@ class Post(models.Model): disclaimer = models.BooleanField(blank=True, default=False) books = models.ManyToManyField(Book, blank=True) old_image = models.FileField(upload_to=get_upload_path, blank=True, null=True, help_text="should be 520 by 290") + trip = models.ManyToManyField(Trip, blank=True, null=True) related = models.ManyToManyField(RelatedPost, blank=True) point = models.PointField(null=True, blank=True) location = models.ForeignKey(Location, on_delete=models.CASCADE, null=True, blank=True) |