From 2b539a45d20cfed4f7c42e3f5b780743e646cdb2 Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Mon, 3 Jul 2023 20:52:43 +0200 Subject: [PATCH] Set subs per product category --- backend/zetikettes/tikette/models.py | 24 +++++++++++------------ backend/zetikettes/tikette/views.py | 2 +- backend/zetikettes/zetikettes/settings.py | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/zetikettes/tikette/models.py b/backend/zetikettes/tikette/models.py index 9d7af6a..f2b4701 100644 --- a/backend/zetikettes/tikette/models.py +++ b/backend/zetikettes/tikette/models.py @@ -1,16 +1,5 @@ from django.db import models -class Tikategory(models.Model): - name = models.CharField(max_length=50) - landscape = models.BooleanField() - - def __str__(self): - return self.name - - class Meta: - verbose_name_plural = "tikategoriez" - - class Tisub(models.Model): name = models.CharField(max_length=50) descritpion = models.TextField() @@ -23,11 +12,22 @@ class Tisub(models.Model): verbose_name_plural = "tisubz" +class Tikategory(models.Model): + name = models.CharField(max_length=50) + landscape = models.BooleanField() + subs = models.ManyToManyField(Tisub) + + def __str__(self): + return self.name + + class Meta: + verbose_name_plural = "tikategoriez" + + class Tikette(models.Model): title = models.CharField(max_length=100) category = models.ForeignKey(Tikategory, on_delete=models.CASCADE) svg = models.FileField() - subs = models.ManyToManyField(Tisub) def __str__(self): return self.title diff --git a/backend/zetikettes/tikette/views.py b/backend/zetikettes/tikette/views.py index 210944e..9f974c3 100644 --- a/backend/zetikettes/tikette/views.py +++ b/backend/zetikettes/tikette/views.py @@ -16,7 +16,7 @@ def index(request): 'category': x.category.name, 'sticker': x.svg.name, 'landscape': x.category.landscape, - 'subs': {x.name: x.default for x in x.subs.all()}, + 'subs': {x.name: x.default for x in x.category.subs.all()}, } for x in Tikette.objects.all()] return JsonResponse({'status': 'ok', 'tikettes': tikettes}, headers=CORS) diff --git a/backend/zetikettes/zetikettes/settings.py b/backend/zetikettes/zetikettes/settings.py index 367038a..7bf1059 100644 --- a/backend/zetikettes/zetikettes/settings.py +++ b/backend/zetikettes/zetikettes/settings.py @@ -29,7 +29,7 @@ SECRET_KEY = 'django-insecure-64qxpe55#9wy=5@#dl0)3w7ywxh48m!f&!slp9e7v4lh@hjdct # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ['aerith.ponteilla.net'] +ALLOWED_HOSTS = ['aerith.ponteilla.net', 'localhost'] CSRF_TRUSTED_ORIGINS = ['https://aerith.ponteilla.net']