This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.serializers import serialize | |
from django.http import HttpResponse | |
from .models import Movie | |
def movies_list(request): | |
queryset = Movie.objects.all() | |
content = serialize('json', queryset) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import close_old_connections | |
from asgiref.sync import SyncToAsync | |
class DatabaseSyncToAsync(SyncToAsync): | |
""" | |
SyncToAsync version that cleans up old database connections when it exits. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aiohttp import web | |
from django.apps import apps | |
from django.core.serializers import serialize | |
from mymoviedb.utils import database_sync_to_async | |
routes = web.RouteTableDef() | |
@routes.view('/movies') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aiohttp import web | |
from django import setup | |
from django.conf import settings | |
from mymoviedb import settings as my_settings # not the same as django.conf.settings | |
from movies.routes import movies_app | |
async def setup_django(app): | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Movie(models.Model): | |
release_date = models.DateField() | |
title = models.CharField(max_length=512) | |
rating = models.PositiveSmallIntegerField() | |
duration = models.DurationField() | |
director = models.CharField(max_length=512) | |
genre = models.CharField(max_length=16) |