Remove BabyBuddy prefix from Tags-model

This commit is contained in:
Paul Konstantin Gerke 2022-03-02 21:53:51 +01:00
parent a35df92fe2
commit 4f325ba07b
7 changed files with 63 additions and 120 deletions

View File

@ -204,7 +204,7 @@ class BMISerializer(CoreModelSerializer):
class TagsSerializer(serializers.HyperlinkedModelSerializer): class TagsSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = models.BabyBuddyTag model = models.Tag
fields = ("slug", "name", "color", "last_used") fields = ("slug", "name", "color", "last_used")
extra_kwargs = { extra_kwargs = {
"slug": {"required": False, "read_only": True}, "slug": {"required": False, "read_only": True},

View File

@ -95,7 +95,7 @@ class BMIViewSet(viewsets.ModelViewSet):
class TagsViewSet(viewsets.ModelViewSet): class TagsViewSet(viewsets.ModelViewSet):
queryset = models.BabyBuddyTag.objects.all() queryset = models.Tag.objects.all()
serializer_class = serializers.TagsSerializer serializer_class = serializers.TagsSerializer
lookup_field = "slug" lookup_field = "slug"
filterset_fields = ("last_used", "name") filterset_fields = ("last_used", "name")

View File

@ -179,13 +179,13 @@ class WeightAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
resource_class = WeightImportExportResource resource_class = WeightImportExportResource
class BabyBuddyTaggedItemInline(admin.StackedInline): class TaggedItemInline(admin.StackedInline):
model = models.BabyBuddyTagged model = models.Tagged
@admin.register(models.BabyBuddyTag) @admin.register(models.Tag)
class BabyBuddyTagAdmin(admin.ModelAdmin): class TagAdmin(admin.ModelAdmin):
inlines = [BabyBuddyTaggedItemInline] inlines = [TaggedItemInline]
list_display = ["name", "slug", "color", "last_used"] list_display = ["name", "slug", "color", "last_used"]
ordering = ["name", "slug"] ordering = ["name", "slug"]
search_fields = ["name"] search_fields = ["name"]

View File

@ -1,106 +0,0 @@
# Generated by Django 4.0.2 on 2022-02-15 16:33
import core.models
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import taggit.managers
class Migration(migrations.Migration):
dependencies = [
("contenttypes", "0002_remove_content_type_name"),
("core", "0018_bmi_headcircumference_height"),
]
operations = [
migrations.CreateModel(
name="BabyBuddyTag",
fields=[
(
"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(
default=core.models.random_color,
max_length=32,
validators=[
django.core.validators.RegexValidator("^#[0-9A-F]{6}$")
],
verbose_name="Color",
),
),
("last_used", models.DateTimeField(default=django.utils.timezone.now)),
],
options={
"verbose_name": "Tag",
"verbose_name_plural": "Tags",
},
),
migrations.CreateModel(
name="BabyBuddyTagged",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"object_id",
models.IntegerField(db_index=True, verbose_name="object ID"),
),
(
"content_type",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="%(app_label)s_%(class)s_tagged_items",
to="contenttypes.contenttype",
verbose_name="content type",
),
),
(
"tag",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="%(app_label)s_%(class)s_items",
to="core.babybuddytag",
),
),
],
options={
"abstract": False,
},
),
migrations.AddField(
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

@ -0,0 +1,49 @@
# Generated by Django 4.0.2 on 2022-03-02 20:48
import core.models
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('core', '0018_bmi_headcircumference_height'),
]
operations = [
migrations.CreateModel(
name='Tag',
fields=[
('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(default=core.models.random_color, max_length=32, validators=[django.core.validators.RegexValidator('^#[0-9A-F]{6}$')], verbose_name='Color')),
('last_used', models.DateTimeField(default=django.utils.timezone.now)),
],
options={
'verbose_name': 'Tag',
'verbose_name_plural': 'Tags',
},
),
migrations.CreateModel(
name='Tagged',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('object_id', models.IntegerField(db_index=True, verbose_name='object ID')),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_tagged_items', to='contenttypes.contenttype', verbose_name='content type')),
('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_items', to='core.tag')),
],
options={
'abstract': False,
},
),
migrations.AddField(
model_name='note',
name='tags',
field=core.models.TaggableManager(blank=True, help_text=None, through='core.Tagged', to='core.Tag', verbose_name='Tags'),
),
]

View File

@ -104,7 +104,7 @@ def random_color():
return TAG_COLORS[random.randrange(0, len(TAG_COLORS))] return TAG_COLORS[random.randrange(0, len(TAG_COLORS))]
class BabyBuddyTag(TagBase): class Tag(TagBase):
class Meta: class Meta:
verbose_name = _("Tag") verbose_name = _("Tag")
verbose_name_plural = _("Tags") verbose_name_plural = _("Tags")
@ -122,9 +122,9 @@ class BabyBuddyTag(TagBase):
) )
class BabyBuddyTagged(GenericTaggedItemBase): class Tagged(GenericTaggedItemBase):
tag = models.ForeignKey( tag = models.ForeignKey(
BabyBuddyTag, Tag,
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name="%(app_label)s_%(class)s_items", related_name="%(app_label)s_%(class)s_items",
) )
@ -135,7 +135,7 @@ class BabyBuddyTagged(GenericTaggedItemBase):
return super().save_base(*args, **kwargs) return super().save_base(*args, **kwargs)
class BabyBuddyTaggableManager(TaggableManager): class TaggableManager(TaggableManager):
""" """
Remove default help_text - only reason for this to exist. Remove default help_text - only reason for this to exist.
""" """
@ -325,7 +325,7 @@ class Note(models.Model):
time = models.DateTimeField( time = models.DateTimeField(
default=timezone.now, blank=False, verbose_name=_("Time") default=timezone.now, blank=False, verbose_name=_("Time")
) )
tags = BabyBuddyTaggableManager(blank=True, through=BabyBuddyTagged) tags = TaggableManager(blank=True, through=Tagged)
objects = models.Manager() objects = models.Manager()

View File

@ -12,7 +12,7 @@ class TagsEditor(Widget):
template_name = "core/widget_tag_editor.html" template_name = "core/widget_tag_editor.html"
@staticmethod @staticmethod
def __unpack_tag(tag): def __unpack_tag(tag: models.Tag):
return {"name": tag.name, "color": tag.color} return {"name": tag.name, "color": tag.color}
def format_value(self, value: Any) -> Optional[str]: def format_value(self, value: Any) -> Optional[str]:
@ -28,7 +28,7 @@ class TagsEditor(Widget):
return attrs return attrs
def get_context(self, name: str, value: Any, attrs) -> Dict[str, Any]: def get_context(self, name: str, value: Any, attrs) -> Dict[str, Any]:
most_tags = models.BabyBuddyTag.objects.order_by("-last_used").all()[:256] most_tags = models.Tag.objects.order_by("-last_used").all()[:256]
result = super().get_context(name, value, attrs) result = super().get_context(name, value, attrs)