Set subs per product category

This commit is contained in:
Paul Mathieu 2023-07-03 20:52:43 +02:00
parent 2895d295e4
commit 2b539a45d2
3 changed files with 14 additions and 14 deletions

View File

@ -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

View File

@ -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)

View File

@ -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']