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 tags support to most things #414

Merged
merged 1 commit into from
Mar 8, 2022
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
20 changes: 9 additions & 11 deletions core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.utils.translation import gettext as _

from core import models
from core.widgets import TagsEditor


def set_initial_values(kwargs, form_type):
Expand Down Expand Up @@ -128,7 +127,7 @@ def save(self, commit=True):
class DiaperChangeForm(CoreModelForm):
class Meta:
model = models.DiaperChange
fields = ["child", "time", "wet", "solid", "color", "amount", "notes"]
fields = ["child", "time", "wet", "solid", "color", "amount", "notes", "tags"]
widgets = {
"time": forms.DateTimeInput(
attrs={
Expand All @@ -143,7 +142,7 @@ class Meta:
class FeedingForm(CoreModelForm):
class Meta:
model = models.Feeding
fields = ["child", "start", "end", "type", "method", "amount", "notes"]
fields = ["child", "start", "end", "type", "method", "amount", "notes", "tags"]
widgets = {
"start": forms.DateTimeInput(
attrs={
Expand Down Expand Up @@ -172,14 +171,13 @@ class Meta:
"data-target": "#datetimepicker_time",
}
),
"tags": TagsEditor(),
}


class SleepForm(CoreModelForm):
class Meta:
model = models.Sleep
fields = ["child", "start", "end", "notes"]
fields = ["child", "start", "end", "notes", "tags"]
widgets = {
"start": forms.DateTimeInput(
attrs={
Expand All @@ -200,7 +198,7 @@ class Meta:
class TemperatureForm(CoreModelForm):
class Meta:
model = models.Temperature
fields = ["child", "temperature", "time", "notes"]
fields = ["child", "temperature", "time", "notes", "tags"]
widgets = {
"time": forms.DateTimeInput(
attrs={
Expand Down Expand Up @@ -239,7 +237,7 @@ def save(self, commit=True):
class TummyTimeForm(CoreModelForm):
class Meta:
model = models.TummyTime
fields = ["child", "start", "end", "milestone"]
fields = ["child", "start", "end", "milestone", "tags"]
widgets = {
"start": forms.DateTimeInput(
attrs={
Expand All @@ -259,7 +257,7 @@ class Meta:
class WeightForm(CoreModelForm):
class Meta:
model = models.Weight
fields = ["child", "weight", "date", "notes"]
fields = ["child", "weight", "date", "notes", "tags"]
widgets = {
"date": forms.DateInput(
attrs={
Expand All @@ -274,7 +272,7 @@ class Meta:
class HeightForm(CoreModelForm):
class Meta:
model = models.Height
fields = ["child", "height", "date", "notes"]
fields = ["child", "height", "date", "notes", "tags"]
widgets = {
"date": forms.DateInput(
attrs={
Expand All @@ -289,7 +287,7 @@ class Meta:
class HeadCircumferenceForm(CoreModelForm):
class Meta:
model = models.HeadCircumference
fields = ["child", "head_circumference", "date", "notes"]
fields = ["child", "head_circumference", "date", "notes", "tags"]
widgets = {
"date": forms.DateInput(
attrs={
Expand All @@ -304,7 +302,7 @@ class Meta:
class BMIForm(CoreModelForm):
class Meta:
model = models.BMI
fields = ["child", "bmi", "date", "notes"]
fields = ["child", "bmi", "date", "notes", "tags"]
widgets = {
"date": forms.DateInput(
attrs={
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Generated by Django 4.0.3 on 2022-03-08 12:42

import core.models
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("core", "0019_tag_tagged_note_tags"),
]

operations = [
migrations.AddField(
model_name="bmi",
name="tags",
field=core.models.TaggableManager(
blank=True,
help_text="Click on the tags to add (+) or remove (-) tags or use the text editor to create new tags.",
through="core.Tagged",
to="core.Tag",
verbose_name="Tags",
),
),
migrations.AddField(
model_name="diaperchange",
name="tags",
field=core.models.TaggableManager(
blank=True,
help_text="Click on the tags to add (+) or remove (-) tags or use the text editor to create new tags.",
through="core.Tagged",
to="core.Tag",
verbose_name="Tags",
),
),
migrations.AddField(
model_name="feeding",
name="tags",
field=core.models.TaggableManager(
blank=True,
help_text="Click on the tags to add (+) or remove (-) tags or use the text editor to create new tags.",
through="core.Tagged",
to="core.Tag",
verbose_name="Tags",
),
),
migrations.AddField(
model_name="headcircumference",
name="tags",
field=core.models.TaggableManager(
blank=True,
help_text="Click on the tags to add (+) or remove (-) tags or use the text editor to create new tags.",
through="core.Tagged",
to="core.Tag",
verbose_name="Tags",
),
),
migrations.AddField(
model_name="height",
name="tags",
field=core.models.TaggableManager(
blank=True,
help_text="Click on the tags to add (+) or remove (-) tags or use the text editor to create new tags.",
through="core.Tagged",
to="core.Tag",
verbose_name="Tags",
),
),
migrations.AddField(
model_name="sleep",
name="tags",
field=core.models.TaggableManager(
blank=True,
help_text="Click on the tags to add (+) or remove (-) tags or use the text editor to create new tags.",
through="core.Tagged",
to="core.Tag",
verbose_name="Tags",
),
),
migrations.AddField(
model_name="temperature",
name="tags",
field=core.models.TaggableManager(
blank=True,
help_text="Click on the tags to add (+) or remove (-) tags or use the text editor to create new tags.",
through="core.Tagged",
to="core.Tag",
verbose_name="Tags",
),
),
migrations.AddField(
model_name="tummytime",
name="tags",
field=core.models.TaggableManager(
blank=True,
help_text="Click on the tags to add (+) or remove (-) tags or use the text editor to create new tags.",
through="core.Tagged",
to="core.Tag",
verbose_name="Tags",
),
),
migrations.AddField(
model_name="weight",
name="tags",
field=core.models.TaggableManager(
blank=True,
help_text="Click on the tags to add (+) or remove (-) tags or use the text editor to create new tags.",
through="core.Tagged",
to="core.Tag",
verbose_name="Tags",
),
),
]
19 changes: 17 additions & 2 deletions core/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import random
from datetime import timedelta
from typing import Iterable, Optional

Expand All @@ -12,8 +13,6 @@
from django.utils.translation import gettext_lazy as _
from django.core.validators import RegexValidator

import random

from taggit.managers import TaggableManager as TaggitTaggableManager
from taggit.models import TagBase, GenericTaggedItemBase

Expand Down Expand Up @@ -151,6 +150,13 @@ def __init__(self, *args, **kwargs):
)
super().__init__(*args, **kwargs)

def formfield(self, *args, **kwargs):
# Local import required because .widgets imports .models
from core.widgets import TagsEditor

kwargs["widget"] = TagsEditor
return super().formfield(*args, **kwargs)


class Child(models.Model):
model_name = "child"
Expand Down Expand Up @@ -230,6 +236,7 @@ class DiaperChange(models.Model):
)
amount = models.FloatField(blank=True, null=True, verbose_name=_("Amount"))
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)

objects = models.Manager()

Expand Down Expand Up @@ -299,6 +306,7 @@ class Feeding(models.Model):
)
amount = models.FloatField(blank=True, null=True, verbose_name=_("Amount"))
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)

objects = models.Manager()

Expand Down Expand Up @@ -364,6 +372,7 @@ class Sleep(models.Model):
editable=False, null=True, verbose_name=_("Duration")
)
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)

objects = models.Manager()
naps = NapsManager()
Expand Down Expand Up @@ -414,6 +423,7 @@ class Temperature(models.Model):
)
time = models.DateTimeField(blank=False, null=False, verbose_name=_("Time"))
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)

objects = models.Manager()

Expand Down Expand Up @@ -541,6 +551,7 @@ class TummyTime(models.Model):
milestone = models.CharField(
blank=True, max_length=255, verbose_name=_("Milestone")
)
tags = TaggableManager(blank=True, through=Tagged)

objects = models.Manager()

Expand Down Expand Up @@ -576,6 +587,7 @@ class Weight(models.Model):
weight = models.FloatField(blank=False, null=False, verbose_name=_("Weight"))
date = models.DateField(blank=False, null=False, verbose_name=_("Date"))
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)

objects = models.Manager()

Expand Down Expand Up @@ -603,6 +615,7 @@ class Height(models.Model):
height = models.FloatField(blank=False, null=False, verbose_name=_("Height"))
date = models.DateField(blank=False, null=False, verbose_name=_("Date"))
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)

objects = models.Manager()

Expand Down Expand Up @@ -632,6 +645,7 @@ class HeadCircumference(models.Model):
)
date = models.DateField(blank=False, null=False, verbose_name=_("Date"))
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)

objects = models.Manager()

Expand All @@ -656,6 +670,7 @@ class BMI(models.Model):
bmi = models.FloatField(blank=False, null=False, verbose_name=_("BMI"))
date = models.DateField(blank=False, null=False, verbose_name=_("Date"))
notes = models.TextField(blank=True, null=True, verbose_name=_("Notes"))
tags = TaggableManager(blank=True, through=Tagged)

objects = models.Manager()

Expand Down