From 43eb40b7eedf3e78e4ce8f0e4676175dc62a129e Mon Sep 17 00:00:00 2001 From: Michael Murtaugh Date: Tue, 28 Jan 2025 12:45:39 +0100 Subject: [PATCH] added published flag to creature model --- call/admin.py | 7 +++-- call/forms.py | 6 +---- ...ptions_remove_creature_message_and_more.py | 26 +++++++++++++++++++ call/models.py | 2 +- call/views.py | 1 + 5 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 call/migrations/0003_alter_creature_options_remove_creature_message_and_more.py diff --git a/call/admin.py b/call/admin.py index b42272c..31ebba6 100644 --- a/call/admin.py +++ b/call/admin.py @@ -1,5 +1,8 @@ from django.contrib import admin - from .models import Creature -admin.site.register(Creature) \ No newline at end of file + +class CreatureAdmin(admin.ModelAdmin): + list_display = ["created", "published", "caption",] + list_editable = ["published", ] +admin.site.register(Creature, CreatureAdmin) \ No newline at end of file diff --git a/call/forms.py b/call/forms.py index 5f054c2..b29eb77 100644 --- a/call/forms.py +++ b/call/forms.py @@ -5,10 +5,6 @@ from call.models import Creature class CreatureForm(ModelForm): class Meta: model = Creature - fields = ["image", "caption", "message"] + fields = ["image", "caption"] -class CreatureFormNoImage(ModelForm): - class Meta: - model = Creature - fields = ["caption", "message"] diff --git a/call/migrations/0003_alter_creature_options_remove_creature_message_and_more.py b/call/migrations/0003_alter_creature_options_remove_creature_message_and_more.py new file mode 100644 index 0000000..166067e --- /dev/null +++ b/call/migrations/0003_alter_creature_options_remove_creature_message_and_more.py @@ -0,0 +1,26 @@ +# Generated by Django 5.1.5 on 2025-01-28 11:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('call', '0002_alter_creature_message'), + ] + + operations = [ + migrations.AlterModelOptions( + name='creature', + options={'ordering': ['-created']}, + ), + migrations.RemoveField( + model_name='creature', + name='message', + ), + migrations.AddField( + model_name='creature', + name='published', + field=models.BooleanField(default=True), + ), + ] diff --git a/call/models.py b/call/models.py index df2d824..6ec08fb 100644 --- a/call/models.py +++ b/call/models.py @@ -6,7 +6,7 @@ class Creature(models.Model): caption = models.CharField(max_length=255) created = models.DateTimeField("date created", auto_now_add=True) updated = models.DateTimeField("date updated", auto_now=True) - message = models.TextField(max_length=512, blank=True) + published = models.BooleanField(null=False, default=True) class Meta: ordering = ["-created"] diff --git a/call/views.py b/call/views.py index 97d0435..3d2dd1b 100644 --- a/call/views.py +++ b/call/views.py @@ -28,6 +28,7 @@ class Guestbook(generic.ListView): paginate_by = 20 model=Creature template_name = "call/guestbook.html" + queryset = Creature.objects.filter(published=True) class CreatureDetail(generic.DetailView): model = Creature