Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image field to note #723

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Meta:
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):
Expand Down
1 change: 1 addition & 0 deletions api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def test_get(self):
"id": 1,
"child": 1,
"note": "Fake note.",
"image": None,
"time": "2017-11-17T22:45:00-05:00",
"tags": [],
},
Expand Down
1 change: 1 addition & 0 deletions core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class HeightAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
class NoteImportExportResource(ImportExportResourceBase):
class Meta:
model = models.Note
exclude = ("image",)


@admin.register(models.Note)
Expand Down
2 changes: 2 additions & 0 deletions core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
19 changes: 19 additions & 0 deletions core/migrations/0031_note_image.py
Original file line number Diff line number Diff line change
@@ -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"
),
),
]
3 changes: 3 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion core/templates/core/note_list.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'babybuddy/page.html' %}
{% load datetime i18n widget_tweaks %}
{% load datetime i18n imagekit widget_tweaks %}

{% block title %}{% trans "Notes" %}{% endblock %}

Expand All @@ -26,6 +26,7 @@
{% if not unique_child %}
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Image" %}</th>
<th>{% trans "Note" %}</th>
<th>{% trans "Tags" %}</th>
</tr>
Expand Down Expand Up @@ -54,6 +55,12 @@
{% if not unique_child %}
<td><a href="{% url 'core:child' note.child.slug %}">{{ note.child }}</a></td>
{% endif %}
<td>
{% if note.image %}
{% thumbnail '40x40' note.image as thumb %}
<a href="{{ note.image.url }}" target="_blank"><img src="{{ thumb.url }}" class="img-fluid" /></a>
Dismissed Show dismissed Hide dismissed
{% endif %}
</td>
<td>{{ note.note }}</td>
<td>
{% include "core/render_tag_list.html" with tags=note.tags.all %}
Expand Down