Add buttons to add a meal plan to a specific point in time
This commit is contained in:
parent
d704ddacdd
commit
4e7c5f9495
@ -54,6 +54,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
{% for day_key, days_value in plan_value.days.items %}
|
{% for day_key, days_value in plan_value.days.items %}
|
||||||
<td>
|
<td>
|
||||||
|
<a href="{% url 'new_meal_plan' %}?date={{ day_key|date:'Y-m-d' }}&meal={{ plan_key }}"><i class="fas fa-plus"></i></a><br/>
|
||||||
{% for mp in days_value %}
|
{% for mp in days_value %}
|
||||||
<a href="{% url 'edit_meal_plan' mp.pk %}"><i class="fas fa-edit"></i></a>
|
<a href="{% url 'edit_meal_plan' mp.pk %}"><i class="fas fa-edit"></i></a>
|
||||||
<a href="{% url 'view_recipe' mp.recipe.id %}">{{ mp.recipe.name }}</a><br/>
|
<a href="{% url 'view_recipe' mp.recipe.id %}">{{ mp.recipe.name }}</a><br/>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
@ -120,6 +121,12 @@ class MealPlanCreate(LoginRequiredMixin, CreateView):
|
|||||||
form_class = MealPlanForm
|
form_class = MealPlanForm
|
||||||
success_url = reverse_lazy('view_plan')
|
success_url = reverse_lazy('view_plan')
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
return dict(
|
||||||
|
meal=self.request.GET['meal'] if 'meal' in self.request.GET else None,
|
||||||
|
date=datetime.strptime(self.request.GET['date'], '%Y-%m-%d') if 'date' in self.request.GET else None
|
||||||
|
)
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
obj = form.save(commit=False)
|
obj = form.save(commit=False)
|
||||||
obj.user = self.request.user
|
obj.user = self.request.user
|
||||||
|
Loading…
Reference in New Issue
Block a user