diff --git a/cookbook/forms.py b/cookbook/forms.py index c283857e..b3a925a0 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -31,11 +31,16 @@ class UserPreferenceForm(forms.ModelForm): class Meta: model = UserPreference - fields = ('default_unit', 'theme', 'nav_color', 'default_page', 'search_style') + fields = ('default_unit', 'theme', 'nav_color', 'default_page', 'search_style', 'plan_share') help_texts = { 'nav_color': _('Color of the top navigation bar. Not all colors work with all themes, just try them out!'), - 'default_unit': _('Default Unit to be used when inserting a new ingredient into a recipe.') + 'default_unit': _('Default Unit to be used when inserting a new ingredient into a recipe.'), + 'plan_share': _('Default user to share newly created meal plan entries with.') + } + + widgets = { + 'plan_share': MultiSelectWidget } @@ -257,6 +262,6 @@ class MealPlanForm(forms.ModelForm): class Meta: model = MealPlan - fields = ('recipe', 'title', 'meal', 'note', 'date') + fields = ('recipe', 'title', 'meal', 'note', 'date', 'shared') - widgets = {'recipe': SelectWidget, 'date': DateWidget} + widgets = {'recipe': SelectWidget, 'date': DateWidget, 'shared': MultiSelectWidget} diff --git a/cookbook/migrations/0043_auto_20200507_2302.py b/cookbook/migrations/0043_auto_20200507_2302.py new file mode 100644 index 00000000..c6a13ffc --- /dev/null +++ b/cookbook/migrations/0043_auto_20200507_2302.py @@ -0,0 +1,25 @@ +# Generated by Django 3.0.5 on 2020-05-07 21:02 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('cookbook', '0042_cooklog'), + ] + + operations = [ + migrations.AddField( + model_name='mealplan', + name='shared', + field=models.ManyToManyField(blank=True, related_name='plan_share', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='userpreference', + name='plan_share', + field=models.ManyToManyField(blank=True, related_name='plan_share_default', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index 6a521c46..e6b3b1c4 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -61,6 +61,7 @@ class UserPreference(models.Model): default_unit = models.CharField(max_length=32, default='g') default_page = models.CharField(choices=PAGES, max_length=64, default=SEARCH) search_style = models.CharField(choices=SEARCH_STYLE, max_length=64, default=LARGE) + plan_share = models.ManyToManyField(User, blank=True, related_name='plan_share_default') def __str__(self): return str(self.user) @@ -223,6 +224,7 @@ class MealPlan(models.Model): recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE, blank=True, null=True) title = models.CharField(max_length=64, blank=True, default='') created_by = models.ForeignKey(User, on_delete=models.CASCADE) + shared = models.ManyToManyField(User, blank=True, related_name='plan_share') meal = models.CharField(choices=MEAL_TYPES, max_length=128, default=BREAKFAST) note = models.TextField(blank=True) date = models.DateField() diff --git a/cookbook/templates/settings.html b/cookbook/templates/settings.html index f497373f..9601cf4c 100644 --- a/cookbook/templates/settings.html +++ b/cookbook/templates/settings.html @@ -5,6 +5,11 @@ {% block title %}{% trans 'Settings' %}{% endblock %} +{% block extra_head %} + {{ preference_form.media }} +{% endblock %} + + {% block content %}