diff --git a/config/settings/base.py b/config/settings/base.py index 8086e41..9c87e0d 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -37,6 +37,7 @@ INSTALLED_APPS = [ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + "django.contrib.humanize", "django_bootstrap5", "reinheit.apps.brew", "reinheit.apps.styles", @@ -58,7 +59,7 @@ ROOT_URLCONF = "config.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [BASE_DIR/"reinheit"/"templates"], + "DIRS": [BASE_DIR / "reinheit" / "templates"], "APP_DIRS": True, "OPTIONS": { "context_processors": [ @@ -120,6 +121,7 @@ USE_TZ = True # https://docs.djangoproject.com/en/5.0/howto/static-files/ STATIC_URL = "static/" +STATICFILES_DIRS = [BASE_DIR / "reinheit" / "static"] # Default primary key field type # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field diff --git a/config/urls.py b/config/urls.py index b830bd4..8a4ad6d 100644 --- a/config/urls.py +++ b/config/urls.py @@ -3,6 +3,5 @@ from django.contrib import admin urlpatterns = [ path("admin/", admin.site.urls), - - path("brews/", include(("reinheit.apps.brew.urls", "brew"), namespace="brews")) + path("brews/", include(("reinheit.apps.brew.urls", "brew"), namespace="brews")), ] diff --git a/reinheit/apps/brew/models.py b/reinheit/apps/brew/models.py index f1c74ac..14e66c3 100644 --- a/reinheit/apps/brew/models.py +++ b/reinheit/apps/brew/models.py @@ -27,10 +27,18 @@ class Brew(models.Model): class Addition(models.Model): ingredient = models.ForeignKey("ingredients.Ingredient", on_delete=models.PROTECT) - brew = models.ForeignKey("Brew", on_delete=models.CASCADE) + brew = models.ForeignKey("Brew", on_delete=models.CASCADE, related_name="additions") mass = models.FloatField(help_text="The mass in kg added") added = models.DateTimeField(null=True) + @property + def unit(self): + return "g" if self.mass < 0.5 else "kg" + + @property + def humanised_mass(self): + return 1000 * self.mass if self.mass < 0.5 else self.mass + def __str__(self): return f"{self.mass}kg of {self.ingredient} in {self.brew}" diff --git a/reinheit/apps/brew/urls.py b/reinheit/apps/brew/urls.py index b6936ab..2ea2be7 100644 --- a/reinheit/apps/brew/urls.py +++ b/reinheit/apps/brew/urls.py @@ -1,7 +1,8 @@ from django.urls import path -from .views import BrewListView +from .views import BrewListView, BrewView urlpatterns = [ - path("brews/", BrewListView.as_view(), name="list") + path("brews/", BrewListView.as_view(), name="list"), + path("brews//", BrewView.as_view(), name="brew"), ] diff --git a/reinheit/apps/brew/views.py b/reinheit/apps/brew/views.py index 09ec38c..39060a0 100644 --- a/reinheit/apps/brew/views.py +++ b/reinheit/apps/brew/views.py @@ -1,4 +1,4 @@ -from django.views.generic import ListView +from django.views.generic import ListView, DetailView from .models import Brew @@ -8,7 +8,9 @@ from .models import Brew class BrewListView(ListView): model = Brew + +class BrewView(DetailView): + model = Brew + def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - print(context) - return context + return super().get_context_data(ingredients=self.object.additions.all(), **kwargs) diff --git a/reinheit/static/img/brand.png b/reinheit/static/img/brand.png new file mode 100644 index 0000000..4dc8bc3 Binary files /dev/null and b/reinheit/static/img/brand.png differ diff --git a/reinheit/templates/base.html b/reinheit/templates/base.html index 90531a4..1079dd5 100644 --- a/reinheit/templates/base.html +++ b/reinheit/templates/base.html @@ -1,2 +1,52 @@ - - +{% extends 'django_bootstrap5/bootstrap5.html' %} +{% load static %} +{% block bootstrap5_extra_head %} + +{% endblock %} +{% block bootstrap5_title %}Reinheit{% endblock %} +{% block bootstrap5_before_content %} + {% block nav %} + + {% endblock nav %} +{% endblock %} +{% block bootstrap5_content %} +
+
+
+ {% block content %} + {% endblock content %} +
+
+
+{% endblock bootstrap5_content %} +{% block bootstrap5_after_content %} +
+ +
+{% endblock bootstrap5_after_content %} diff --git a/reinheit/templates/brew/brew_detail.html b/reinheit/templates/brew/brew_detail.html new file mode 100644 index 0000000..392d93a --- /dev/null +++ b/reinheit/templates/brew/brew_detail.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} +{% block content %} +

{{ object.name }}

+

{{ object.style }}

+

{{ object.notes }}

+

Ingredients

+ +{% endblock content %} diff --git a/reinheit/templates/brew/brew_list.html b/reinheit/templates/brew/brew_list.html index 79152df..247ab2b 100644 --- a/reinheit/templates/brew/brew_list.html +++ b/reinheit/templates/brew/brew_list.html @@ -1,8 +1,11 @@ -{% include "base.html" %} - +{% extends "base.html" %} {% block content %} - {% for brew in brew_list %} - {{ brew }} - {% endfor %} - + {% endblock content %} diff --git a/requirements/base.in b/requirements/base.in index 37d30e1..c250a95 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -1,2 +1,3 @@ django django-bootstrap5 +djlint diff --git a/requirements/base.txt b/requirements/base.txt index f86b21e..8764152 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -2,11 +2,45 @@ # uv pip compile requirements/base.in asgiref==3.8.1 # via django +click==8.1.7 + # via djlint +colorama==0.4.6 + # via djlint +cssbeautifier==1.15.1 + # via djlint django==5.0.6 # via # -r requirements/base.in # django-bootstrap5 django-bootstrap5==24.2 # via -r requirements/base.in +djlint==1.34.1 + # via -r requirements/base.in +editorconfig==0.12.4 + # via + # cssbeautifier + # jsbeautifier +html-tag-names==0.1.2 + # via djlint +html-void-elements==0.1.0 + # via djlint +jsbeautifier==1.15.1 + # via + # cssbeautifier + # djlint +json5==0.9.25 + # via djlint +pathspec==0.12.1 + # via djlint +pyyaml==6.0.1 + # via djlint +regex==2023.12.25 + # via djlint +six==1.16.0 + # via + # cssbeautifier + # jsbeautifier sqlparse==0.5.0 # via django +tqdm==4.66.4 + # via djlint