Skip to content
Snippets Groups Projects
Commit fe6e0d6b authored by Maximilian Sjöström's avatar Maximilian Sjöström
Browse files

kommit längre på backend

parent 105a53e9
No related branches found
No related tags found
1 merge request!5Backend
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
from django.contrib import admin
from .models import Product
from .models import Category
# Register your models here.
admin.site.register(Product)
admin.site.register(Category)
......@@ -8,27 +8,11 @@ from django.contrib.auth.models import AbstractUser
class Category(models.Model):
CATEGORY_CHOICES = [
"Christmas",
"Halloween",
"College",
"Easter",
"Disco",
"Afterski",
"Whiteparty",
"Bachelor",
"Ice hockey",
"Football",
"Valentines Day",
"Hawaii",
"Vacation",
"Kräftskiva",
"Midsommar",
"October fest"
]
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Product(models.Model):
# user_id = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
......@@ -42,3 +26,24 @@ class Product(models.Model):
def __str__(self):
return self.name
# CATEGORY_CHOICES = [
# "Christmas",
# "Halloween",
# "College",
# "Easter",
# "Disco",
# "Afterski",
# "Whiteparty",
# "Bachelor",
# "Ice hockey",
# "Football",
# "Valentines Day",
# "Hawaii",
# "Vacation",
# "Kräftskiva",
# "Midsommar",
# "October fest"
# ]
\ No newline at end of file
# myapp/serializers.py
from rest_framework import serializers
from .models import Product
from .models import Category
class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
fields = '__all__'
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = '__all__'
......@@ -2,9 +2,11 @@
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import ProductViewSet
from .views import CategoryViewSet
router = DefaultRouter()
router.register(r'products', ProductViewSet)
router.register(r'categories', CategoryViewSet)
urlpatterns = [
path('', include(router.urls)),
......
......@@ -2,9 +2,14 @@
from rest_framework import viewsets
from .models import Product
from .serializers import ProductSerializer
from .models import Category
from .serializers import CategorySerializer
class ProductViewSet(viewsets.ModelViewSet):
queryset = Product.objects.all()
serializer_class = ProductSerializer
class CategoryViewSet(viewsets.ModelViewSet):
queryset = Category.objects.all()
serializer_class = CategorySerializer
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment