WIP meal plan and icon stuff

This commit is contained in:
vabene1111
2023-08-29 14:36:57 +02:00
parent ce84b3b385
commit 7f62ec28e3
5 changed files with 103 additions and 44 deletions

View File

@@ -0,0 +1,52 @@
# Generated by Django 4.1.10 on 2023-08-29 11:59
from django.db import migrations
from django.db.models import F, Value
from django.db.models.functions import Concat
from django_scopes import scopes_disabled
def migrate_icons(apps, schema_editor):
with scopes_disabled():
MealType = apps.get_model('cookbook', 'MealType')
Keyword = apps.get_model('cookbook', 'Keyword')
PropertyType = apps.get_model('cookbook', 'PropertyType')
RecipeBook = apps.get_model('cookbook', 'RecipeBook')
MealType.objects.update(name=Concat(F('icon'), Value(' '), F('name')))
Keyword.objects.update(name=Concat(F('icon'), Value(' '), F('name')))
PropertyType.objects.update(name=Concat(F('icon'), Value(' '), F('name')))
RecipeBook.objects.update(name=Concat(F('icon'), Value(' '), F('name')))
class Migration(migrations.Migration):
dependencies = [
('cookbook', '0199_alter_propertytype_options_alter_automation_type_and_more'),
]
operations = [
migrations.RunPython(
migrate_icons
),
migrations.AlterModelOptions(
name='propertytype',
options={'ordering': ('order',)},
),
migrations.RemoveField(
model_name='keyword',
name='icon',
),
migrations.RemoveField(
model_name='mealtype',
name='icon',
),
migrations.RemoveField(
model_name='propertytype',
name='icon',
),
migrations.RemoveField(
model_name='recipebook',
name='icon',
),
]

View File

@@ -116,10 +116,7 @@ class TreeModel(MP_Node):
_full_name_separator = ' > '
def __str__(self):
if self.icon:
return f"{self.icon} {self.name}"
else:
return f"{self.name}"
return f"{self.name}"
@property
def parent(self):
@@ -533,7 +530,6 @@ class Keyword(ExportModelOperationsMixin('keyword'), TreeModel, PermissionModelM
if SORT_TREE_BY_NAME:
node_order_by = ['name']
name = models.CharField(max_length=64)
icon = models.CharField(max_length=16, blank=True, null=True)
description = models.TextField(default="", blank=True)
created_at = models.DateTimeField(auto_now_add=True) # TODO deprecate
updated_at = models.DateTimeField(auto_now=True) # TODO deprecate
@@ -767,7 +763,6 @@ class PropertyType(models.Model, PermissionModelMixin):
name = models.CharField(max_length=128)
unit = models.CharField(max_length=64, blank=True, null=True)
icon = models.CharField(max_length=16, blank=True, null=True)
order = models.IntegerField(default=0)
description = models.CharField(max_length=512, blank=True, null=True)
category = models.CharField(max_length=64, choices=((NUTRITION, _('Nutrition')), (ALLERGEN, _('Allergen')),
@@ -937,7 +932,6 @@ class RecipeImport(models.Model, PermissionModelMixin):
class RecipeBook(ExportModelOperationsMixin('book'), models.Model, PermissionModelMixin):
name = models.CharField(max_length=128)
description = models.TextField(blank=True)
icon = models.CharField(max_length=16, blank=True, null=True)
shared = models.ManyToManyField(User, blank=True, related_name='shared_with')
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
filter = models.ForeignKey('cookbook.CustomFilter', null=True, blank=True, on_delete=models.SET_NULL)
@@ -980,7 +974,6 @@ class RecipeBookEntry(ExportModelOperationsMixin('book_entry'), models.Model, Pe
class MealType(models.Model, PermissionModelMixin):
name = models.CharField(max_length=128)
order = models.IntegerField(default=0)
icon = models.CharField(max_length=16, blank=True, null=True)
color = models.CharField(max_length=7, blank=True, null=True)
default = models.BooleanField(default=False, blank=True)
created_by = models.ForeignKey(User, on_delete=models.CASCADE)