Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beer model with swagger integration #22

Open
wants to merge 1 commit into
base: backend/stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
.idea
3 changes: 0 additions & 3 deletions backend/beers/admin.py

This file was deleted.

2 changes: 2 additions & 0 deletions backend/beers/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from django import forms
from django.contrib.auth.models import User
29 changes: 28 additions & 1 deletion backend/beers/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
from django.db import models

# Create your models here.
CRAFT = "CR"
NORMAL = "RE"

CRAFT_REGULAR_CHOICES = [
(CRAFT, "Craft"),
(NORMAL, "Normal"),
]


class BeerModel(models.Model):
name = models.CharField(max_length=100)
description = models.TextField()
alcohol = models.FloatField()
price = models.FloatField()
color_type = models.CharField(max_length=20)
image = models.ImageField(upload_to="beers")
extract_content = models.FloatField()
ibu = models.FloatField()
style = models.CharField(max_length=100)
pasteurized = models.BooleanField()
craft_regular = models.CharField(
max_length=2,
choices=CRAFT_REGULAR_CHOICES,
default=NORMAL,
)

def __str__(self):
return self.name
8 changes: 8 additions & 0 deletions backend/beers/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import BeerModel


class BeerSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = BeerModel
fields = '__all__'
13 changes: 12 additions & 1 deletion backend/beers/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
from django.shortcuts import render
from rest_framework import permissions, viewsets
from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiExample
from drf_spectacular.types import OpenApiTypes

from .models import BeerModel
from .serializers import BeerSerializer


class BeerView(viewsets.ModelViewSet):
queryset = BeerModel.objects.all().order_by('name')
serializer_class = BeerSerializer
permission_classes = [permissions.IsAuthenticated]

# Create your views here.
Binary file modified backend/db.sqlite3
Binary file not shown.
17 changes: 17 additions & 0 deletions backend/moj_browarek/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.contrib import admin
from django.contrib import admin

from user.models import UserProfile
from user.forms import UserProfileForm

from beers.models import BeerModel


@admin.register(UserProfile)
class UserProfileAdmin(admin.ModelAdmin):
form = UserProfileForm


@admin.register(BeerModel)
class BeerModelAdmin(admin.ModelAdmin):
pass
3 changes: 2 additions & 1 deletion backend/moj_browarek/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"django.contrib.staticfiles",
"rest_framework",
"drf_spectacular",
'user'
'user',
'beers',
]

MIDDLEWARE = [
Expand Down
2 changes: 2 additions & 0 deletions backend/moj_browarek/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

# imports
from user.views import UserViewSet, UserProfileViewSet
from beers.views import BeerView

router = routers.DefaultRouter()
router.register(r"users", UserViewSet)
router.register(r"profiles", UserProfileViewSet)
router.register(r"beers", BeerView)

urlpatterns = [
path("admin/", admin.site.urls),
Expand Down
10 changes: 0 additions & 10 deletions backend/user/admin.py

This file was deleted.

3 changes: 2 additions & 1 deletion backend/user/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ["id", "username", "email", "first_name", "last_name"] ## todo add group field in the future
fields = ["id", "username", "email", "first_name", "last_name"]
## todo add group field in the future


class UserProfileSerializer(serializers.HyperlinkedModelSerializer):
Expand Down