Fix storing of tags

This commit is contained in:
Paul Konstantin Gerke 2022-02-15 15:46:07 +01:00
parent bf49cc92ad
commit 56ebbd3181
9 changed files with 11 additions and 122 deletions

View File

@ -82,6 +82,7 @@ class CoreModelForm(forms.ModelForm):
timer.stop(instance.end)
if commit:
instance.save()
self.save_m2m()
return instance
@ -169,7 +170,7 @@ class NoteForm(CoreModelForm):
"data-target": "#datetimepicker_time",
}
),
#"tags": TagsEditor()
"tags": TagsEditor()
}

View File

@ -1,7 +1,9 @@
# Generated by Django 4.0.2 on 2022-02-11 15:44
# Generated by Django 4.0.2 on 2022-02-15 14:43
import core.models
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import taggit.managers
@ -9,7 +11,7 @@ class Migration(migrations.Migration):
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('core', '0019_note_tags'),
('core', '0018_bmi_headcircumference_height'),
]
operations = [
@ -19,7 +21,8 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, unique=True, verbose_name='name')),
('slug', models.SlugField(max_length=100, unique=True, verbose_name='slug')),
('color', models.CharField(max_length=32, verbose_name='Color')),
('color', models.CharField(default='#7F7F7F', max_length=32, validators=[core.models.validate_html_color], verbose_name='Color')),
('last_used', models.DateTimeField(default=django.utils.timezone.now)),
],
options={
'verbose_name': 'Tag',
@ -38,9 +41,9 @@ class Migration(migrations.Migration):
'abstract': False,
},
),
migrations.AlterField(
migrations.AddField(
model_name='note',
name='tags',
field=taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='core.BabyBuddyTagged', to='core.BabyBuddyTag', verbose_name='Tags'),
field=taggit.managers.TaggableManager(blank=True, help_text='A comma-separated list of tags.', through='core.BabyBuddyTagged', to='core.BabyBuddyTag', verbose_name='Tags'),
),
]

View File

@ -1,20 +0,0 @@
# Generated by Django 4.0.2 on 2022-02-11 10:47
from django.db import migrations
import taggit.managers
class Migration(migrations.Migration):
dependencies = [
('taggit', '0004_alter_taggeditem_content_type_alter_taggeditem_tag'),
('core', '0018_bmi_headcircumference_height'),
]
operations = [
migrations.AddField(
model_name='note',
name='tags',
field=taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'),
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 4.0.2 on 2022-02-11 17:27
import core.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0020_babybuddytag_babybuddytagged_alter_note_tags'),
]
operations = [
migrations.AlterField(
model_name='babybuddytag',
name='color',
field=models.CharField(default='#7F7F7F', max_length=32, validators=[core.models.validate_html_color], verbose_name='Color'),
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 4.0.2 on 2022-02-13 13:04
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('core', '0021_alter_babybuddytag_color'),
]
operations = [
migrations.AddField(
model_name='babybuddytag',
name='last_used',
field=models.DateTimeField(default=django.utils.timezone.now),
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 4.0.2 on 2022-02-14 15:50
from django.db import migrations
import taggit.managers
class Migration(migrations.Migration):
dependencies = [
('core', '0022_babybuddytag_last_used'),
]
operations = [
migrations.AlterField(
model_name='note',
name='tags',
field=taggit.managers.TaggableManager(blank=True, help_text='A comma-separated list of tags.', through='core.BabyBuddyTagged', to='core.BabyBuddyTag', verbose_name='Tags'),
),
]

View File

@ -1,20 +0,0 @@
# Generated by Django 4.0.2 on 2022-02-15 09:11
from django.db import migrations
import taggit.managers
class Migration(migrations.Migration):
dependencies = [
('taggit', '0004_alter_taggeditem_content_type_alter_taggeditem_tag'),
('core', '0023_alter_note_tags'),
]
operations = [
migrations.AlterField(
model_name='note',
name='tags',
field=taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'),
),
]

View File

@ -94,10 +94,6 @@ class BabyBuddyTag(TagBase):
blank=False,
)
def save(self, *args, **kwargs):
print("BBT SAVE")
return super().save(*args, **kwargs)
class BabyBuddyTagged(GenericTaggedItemBase):
tag = models.ForeignKey(
@ -106,10 +102,6 @@ class BabyBuddyTagged(GenericTaggedItemBase):
related_name="%(app_label)s_%(class)s_items",
)
def save(self, *args, **kwargs) -> None:
print("BabyBuddyTagged", args, kwargs)
return super().save(*args, **kwargs)
class Child(models.Model):
model_name = "child"
first_name = models.CharField(max_length=255, verbose_name=_("First name"))
@ -280,15 +272,6 @@ class Feeding(models.Model):
validate_duration(self)
validate_unique_period(Feeding.objects.filter(child=self.child), self)
from taggit.managers import _TaggableManager
class TTT(_TaggableManager):
def set(self, tags, *, through_defaults=None, **kwargs):
return super().set(tags, through_defaults=through_defaults, **kwargs)
class TT(TaggableManager):
def save_form_data(self, instance, value):
return super().save_form_data(instance, value)
class Note(models.Model):
model_name = "note"
child = models.ForeignKey(
@ -298,7 +281,7 @@ class Note(models.Model):
time = models.DateTimeField(
default=timezone.now, blank=False, verbose_name=_("Time")
)
tags = TaggableManager()
tags = TaggableManager(blank=True, through=BabyBuddyTagged)
objects = models.Manager()

View File

@ -10,7 +10,6 @@ class TagsEditor(Widget):
return {'name': tag.name, 'color': tag.color}
def format_value(self, value: Any) -> Optional[str]:
print("FORMAT", value)
if value is not None and not isinstance(value, str):
value = [self.__unpack_tag(tag) for tag in value]
return value