Last active
June 8, 2020 18:07
-
-
Save pydanny/3c866ce8b4566d8627e5aa995f0134b2 to your computer and use it in GitHub Desktop.
simple_async_update_view.py
This file contains hidden or 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.contrib.auth.mixins import LoginRequiredMixin | |
from django.shortcuts import render, redirect | |
from django.views.generic import View | |
from asgiref.sync import sync_to_async | |
class AsyncViewMixin: | |
async def __call__(self): | |
return super().__call__(self) | |
class SimpleBookUpdateView(LoginRequiredMixin, AsyncViewMixin, View): | |
def get(self, request, *args, **kwargs): | |
return render(request, "test.html", {"book": Book.objects.first()}) | |
def post(self, request, *args, **kwargs): | |
book = Book.objects.first() | |
book.title += "1" | |
sync_to_async(book.save()) | |
return redirect("books:simple") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment