diff --git a/api/serializers.py b/api/serializers.py index 3bb6dae0..794a99fe 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -179,7 +179,7 @@ class HeightSerializer(CoreModelSerializer, TaggableSerializer): class NoteSerializer(CoreModelSerializer, TaggableSerializer): class Meta: model = models.Note - fields = ("id", "child", "note", "time", "tags") + fields = ("id", "child", "note", "image", "time", "tags") class SleepSerializer(CoreModelWithDurationSerializer, TaggableSerializer): diff --git a/api/tests.py b/api/tests.py index 546ee5b1..61f94941 100644 --- a/api/tests.py +++ b/api/tests.py @@ -479,6 +479,7 @@ class NoteAPITestCase(TestBase.BabyBuddyAPITestCaseBase): "id": 1, "child": 1, "note": "Fake note.", + "image": None, "time": "2017-11-17T22:45:00-05:00", "tags": [], }, diff --git a/core/admin.py b/core/admin.py index e082191a..621c125c 100644 --- a/core/admin.py +++ b/core/admin.py @@ -173,6 +173,7 @@ class HeightAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin): class NoteImportExportResource(ImportExportResourceBase): class Meta: model = models.Note + exclude = ("image",) @admin.register(models.Note) diff --git a/core/forms.py b/core/forms.py index 62a2da65..3c11f832 100644 --- a/core/forms.py +++ b/core/forms.py @@ -186,6 +186,8 @@ class NoteForm(CoreModelForm, TaggableModelForm): class Meta: model = models.Note fields = ["child", "note", "time", "tags"] + if settings.BABY_BUDDY["ALLOW_UPLOADS"]: + fields.insert(2, "image") widgets = { "child": ChildRadioSelect, "time": DateTimeInput(), diff --git a/core/migrations/0031_note_image.py b/core/migrations/0031_note_image.py new file mode 100644 index 00000000..db7d0de3 --- /dev/null +++ b/core/migrations/0031_note_image.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.5 on 2023-10-20 23:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("core", "0030_weightpercentile_weightpercentile_unique_age_sex"), + ] + + operations = [ + migrations.AddField( + model_name="note", + name="image", + field=models.ImageField( + blank=True, null=True, upload_to="notes/images/", verbose_name="Image" + ), + ), + ] diff --git a/core/models.py b/core/models.py index 3c41c7be..0b53d588 100644 --- a/core/models.py +++ b/core/models.py @@ -404,6 +404,9 @@ class Note(models.Model): time = models.DateTimeField( blank=False, default=timezone.localtime, verbose_name=_("Time") ) + image = models.ImageField( + blank=True, null=True, upload_to="notes/images/", verbose_name=_("Image") + ) tags = TaggableManager(blank=True, through=Tagged) objects = models.Manager() diff --git a/core/templates/core/note_list.html b/core/templates/core/note_list.html index 40f68578..7d67186c 100644 --- a/core/templates/core/note_list.html +++ b/core/templates/core/note_list.html @@ -1,5 +1,5 @@ {% extends 'babybuddy/page.html' %} -{% load datetime i18n widget_tweaks %} +{% load datetime i18n imagekit widget_tweaks %} {% block title %}{% trans "Notes" %}{% endblock %} @@ -26,6 +26,7 @@ {% if not unique_child %} {% trans "Child" %} {% endif %} + {% trans "Image" %} {% trans "Note" %} {% trans "Tags" %} @@ -54,6 +55,12 @@ {% if not unique_child %} {{ note.child }} {% endif %} + + {% if note.image %} + {% thumbnail '40x40' note.image as thumb %} + + {% endif %} + {{ note.note }} {% include "core/render_tag_list.html" with tags=note.tags.all %}