refacto [api]: split views files + some

This commit is contained in:
Alice 2022-04-03 01:20:54 +02:00
parent 7fe4186105
commit 67fd010e10
5 changed files with 9 additions and 17 deletions

View file

@ -5,8 +5,8 @@ TODO implement validators
- nullable or sure - nullable or sure
""" """
class Film(models.Model):
class Film(models.Model):
class MovieFormat(models.TextChoices): class MovieFormat(models.TextChoices):
ANALOG_35 = '35mm' ANALOG_35 = '35mm'
DVD = 'DVD' DVD = 'DVD'
@ -34,4 +34,3 @@ class Film(models.Model):
def __str__(self): def __str__(self):
return f'{self.title} de {self.director} ({self.projection_date.strftime("%d/%m/%Y")})' return f'{self.title} de {self.director} ({self.projection_date.strftime("%d/%m/%Y")})'

View file

@ -1,9 +1,9 @@
from django.urls import include, path from django.urls import include, path
from rest_framework import routers from rest_framework import routers
from . import views from .views.std_views import (FilmViewSet)
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'films', views.FilmViewSet) router.register(r'films', FilmViewSet)
# Wire up our API using automatic URL routing. # Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API. # Additionally, we include login URLs for the browsable API.

View file

@ -1,8 +1,9 @@
# from django.shortcuts import render # from django.shortcuts import render
from rest_framework import viewsets from rest_framework import viewsets
from .serializers import FilmSerializer from myapi.serializers import FilmSerializer
from .models import Film from myapi.models import Film
class FilmViewSet(viewsets.ModelViewSet): class FilmViewSet(viewsets.ModelViewSet):
queryset = Film.objects.all().order_by('projection_date') queryset = Film.objects.all().order_by('projection_date')

View file

@ -1,2 +1,3 @@
Django>=3.0,<4.0 Django>=3.2,<3.3
psycopg2>=2.8 djangorestframework==3.13.1
django-cors-headers==3.5.0

View file

@ -125,12 +125,3 @@ STATIC_URL = '/static/'
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': [
'rest_framework.renderers.JSONRenderer',
],
'DEFAULT_PARSER_CLASSES': [
'rest_framework.parsers.JSONParser',
]
}