mirror of https://github.com/snachodog/mybuddy.git
Add image field to note
This commit is contained in:
parent
ed18fc865e
commit
b54499d6f2
|
@ -179,7 +179,7 @@ class HeightSerializer(CoreModelSerializer, TaggableSerializer):
|
||||||
class NoteSerializer(CoreModelSerializer, TaggableSerializer):
|
class NoteSerializer(CoreModelSerializer, TaggableSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Note
|
model = models.Note
|
||||||
fields = ("id", "child", "note", "time", "tags")
|
fields = ("id", "child", "note", "image", "time", "tags")
|
||||||
|
|
||||||
|
|
||||||
class SleepSerializer(CoreModelWithDurationSerializer, TaggableSerializer):
|
class SleepSerializer(CoreModelWithDurationSerializer, TaggableSerializer):
|
||||||
|
|
|
@ -479,6 +479,7 @@ class NoteAPITestCase(TestBase.BabyBuddyAPITestCaseBase):
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"child": 1,
|
"child": 1,
|
||||||
"note": "Fake note.",
|
"note": "Fake note.",
|
||||||
|
"image": None,
|
||||||
"time": "2017-11-17T22:45:00-05:00",
|
"time": "2017-11-17T22:45:00-05:00",
|
||||||
"tags": [],
|
"tags": [],
|
||||||
},
|
},
|
||||||
|
|
|
@ -173,6 +173,7 @@ class HeightAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
||||||
class NoteImportExportResource(ImportExportResourceBase):
|
class NoteImportExportResource(ImportExportResourceBase):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Note
|
model = models.Note
|
||||||
|
exclude = ("image",)
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.Note)
|
@admin.register(models.Note)
|
||||||
|
|
|
@ -186,6 +186,8 @@ class NoteForm(CoreModelForm, TaggableModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Note
|
model = models.Note
|
||||||
fields = ["child", "note", "time", "tags"]
|
fields = ["child", "note", "time", "tags"]
|
||||||
|
if settings.BABY_BUDDY["ALLOW_UPLOADS"]:
|
||||||
|
fields.insert(2, "image")
|
||||||
widgets = {
|
widgets = {
|
||||||
"child": ChildRadioSelect,
|
"child": ChildRadioSelect,
|
||||||
"time": DateTimeInput(),
|
"time": DateTimeInput(),
|
||||||
|
|
|
@ -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"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -404,6 +404,9 @@ class Note(models.Model):
|
||||||
time = models.DateTimeField(
|
time = models.DateTimeField(
|
||||||
blank=False, default=timezone.localtime, verbose_name=_("Time")
|
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)
|
tags = TaggableManager(blank=True, through=Tagged)
|
||||||
|
|
||||||
objects = models.Manager()
|
objects = models.Manager()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% extends 'babybuddy/page.html' %}
|
{% extends 'babybuddy/page.html' %}
|
||||||
{% load datetime i18n widget_tweaks %}
|
{% load datetime i18n imagekit widget_tweaks %}
|
||||||
|
|
||||||
{% block title %}{% trans "Notes" %}{% endblock %}
|
{% block title %}{% trans "Notes" %}{% endblock %}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
||||||
{% if not unique_child %}
|
{% if not unique_child %}
|
||||||
<th>{% trans "Child" %}</th>
|
<th>{% trans "Child" %}</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<th>{% trans "Image" %}</th>
|
||||||
<th>{% trans "Note" %}</th>
|
<th>{% trans "Note" %}</th>
|
||||||
<th>{% trans "Tags" %}</th>
|
<th>{% trans "Tags" %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -54,6 +55,12 @@
|
||||||
{% if not unique_child %}
|
{% if not unique_child %}
|
||||||
<td><a href="{% url 'core:child' note.child.slug %}">{{ note.child }}</a></td>
|
<td><a href="{% url 'core:child' note.child.slug %}">{{ note.child }}</a></td>
|
||||||
{% endif %}
|
{% 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>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
<td>{{ note.note }}</td>
|
<td>{{ note.note }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% include "core/render_tag_list.html" with tags=note.tags.all %}
|
{% include "core/render_tag_list.html" with tags=note.tags.all %}
|
||||||
|
|
Loading…
Reference in New Issue