From ae2a46ea60239295b16f5f2770cdca50eb8c9979 Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Sun, 30 Jun 2024 13:40:18 +0100 Subject: [PATCH] Do some shit with views or whatever --- .../apps/shopping/migrations/0001_initial.py | 67 +++++++++++++++++++ reinheit/apps/shopping/urls.py | 9 +++ reinheit/apps/shopping/views.py | 16 ++++- reinheit/templates/base.html | 3 + .../templates/shopping/shoppinglist_form.html | 14 ++++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 reinheit/apps/shopping/migrations/0001_initial.py create mode 100644 reinheit/apps/shopping/urls.py create mode 100644 reinheit/templates/shopping/shoppinglist_form.html diff --git a/reinheit/apps/shopping/migrations/0001_initial.py b/reinheit/apps/shopping/migrations/0001_initial.py new file mode 100644 index 0000000..8e247c9 --- /dev/null +++ b/reinheit/apps/shopping/migrations/0001_initial.py @@ -0,0 +1,67 @@ +# Generated by Django 5.0.6 on 2024-06-30 12:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Item", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name="Recipe", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=255)), + ( + "time_required", + models.PositiveIntegerField( + choices=[(1, "Low"), (2, "Medium"), (3, "High")] + ), + ), + ("ingredients", models.ManyToManyField(to="shopping.item")), + ], + ), + migrations.CreateModel( + name="ShoppingList", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("date", models.DateField()), + ("meals", models.ManyToManyField(to="shopping.recipe")), + ("other", models.ManyToManyField(to="shopping.item")), + ], + ), + ] diff --git a/reinheit/apps/shopping/urls.py b/reinheit/apps/shopping/urls.py new file mode 100644 index 0000000..0fcc743 --- /dev/null +++ b/reinheit/apps/shopping/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from .views import ShoppingListDetailView, ShoppingListCreateView + +urlpatterns = [ + path("", ShoppingListDetailView.as_view(), name="current"), + path("new/", ShoppingListCreateView.as_view(), name="new"), + +] diff --git a/reinheit/apps/shopping/views.py b/reinheit/apps/shopping/views.py index 91ea44a..513ca67 100644 --- a/reinheit/apps/shopping/views.py +++ b/reinheit/apps/shopping/views.py @@ -1,3 +1,17 @@ -from django.shortcuts import render +from django.views.generic import DetailView, CreateView + +from .models import ShoppingList # Create your views here. + + +class ShoppingListDetailView(DetailView): + model = ShoppingList + + def get_object(self): + return self.model.objects.latest("date") + + +class ShoppingListCreateView(CreateView): + model = ShoppingList + fields = ("date", "meals", "other") diff --git a/reinheit/templates/base.html b/reinheit/templates/base.html index 97bfb23..fffd1cc 100644 --- a/reinheit/templates/base.html +++ b/reinheit/templates/base.html @@ -21,6 +21,9 @@ + diff --git a/reinheit/templates/shopping/shoppinglist_form.html b/reinheit/templates/shopping/shoppinglist_form.html new file mode 100644 index 0000000..3c7bc69 --- /dev/null +++ b/reinheit/templates/shopping/shoppinglist_form.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} +{% load django_bootstrap5 %} + +{% block content %} +
+
+
+ {% csrf_token %} + {% bootstrap_form form %} + {% bootstrap_button "Create" %} +
+
+
+{% endblock content %}