diff --git a/examples/asyncorm/__main__.py b/examples/asyncorm/__main__.py index 6e4d4ff2..f7fca250 100644 --- a/examples/asyncorm/__main__.py +++ b/examples/asyncorm/__main__.py @@ -16,8 +16,8 @@ app = Sanic(name=__name__) def orm_configure(sanic, loop): db_config = {'database': 'sanic_example', 'host': 'localhost', - 'user': 'sanicdbuser', - 'password': 'sanicDbPass', + 'user': 'ormdbuser', + 'password': 'ormDbPass', } # configure_orm needs a dictionary with: @@ -44,6 +44,15 @@ def ignore_404s(request, exception): }) +@app.exception(URLBuildError) +def ignore_urlbuilderrors(request, exception): + return json({'method': request.method, + 'status': exception.status_code, + 'error': exception.args[0], + 'results': None, + }) + + # now the propper sanic workflow class BooksView(HTTPMethodView): @@ -80,6 +89,7 @@ class BooksView(HTTPMethodView): 'results': BookSerializer.serialize(book), }) + class BookView(HTTPMethodView): async def get_object(self, request, book_id): try: @@ -136,4 +146,4 @@ app.add_route(BooksView.as_view(), '/books/') app.add_route(BookView.as_view(), '/books//') if __name__ == '__main__': - app.run() + app.run(port=9000, debug=True) diff --git a/examples/asyncorm/library/models.py b/examples/asyncorm/library/models.py index 51cacb1b..b1a0749f 100644 --- a/examples/asyncorm/library/models.py +++ b/examples/asyncorm/library/models.py @@ -1,5 +1,4 @@ -from asyncorm.model import Model -from asyncorm.fields import CharField, IntegerField, DateField +from asyncorm import models BOOK_CHOICES = ( @@ -9,13 +8,17 @@ BOOK_CHOICES = ( # This is a simple model definition -class Book(Model): - name = CharField(max_length=50) - synopsis = CharField(max_length=255) - book_type = CharField(max_length=15, null=True, choices=BOOK_CHOICES) - pages = IntegerField(null=True) - date_created = DateField(auto_now=True) +class Book(models.Model): + name = models.CharField(max_length=50) + synopsis = models.CharField(max_length=255) + book_type = models.CharField( + max_length=15, + null=True, + choices=BOOK_CHOICES + ) + pages = models.IntegerField(null=True) + date_created = models.DateField(auto_now=True) class Meta(): - ordering = ['name', ] + ordering = ['-name', ] unique_together = ['name', 'synopsis'] diff --git a/examples/asyncorm/library/serializer.py b/examples/asyncorm/library/serializer.py index 00faa91e..a31d5897 100644 --- a/examples/asyncorm/library/serializer.py +++ b/examples/asyncorm/library/serializer.py @@ -1,4 +1,4 @@ -from asyncorm.model import ModelSerializer, SerializerMethod +from asyncorm.serializers import ModelSerializer, SerializerMethod from library.models import Book diff --git a/examples/asyncorm/requirements.txt b/examples/asyncorm/requirements.txt index b4aa9cae..e9f21a88 100644 --- a/examples/asyncorm/requirements.txt +++ b/examples/asyncorm/requirements.txt @@ -1,2 +1,3 @@ -asyncorm==0.0.9 +asyncorm>=0.0.9 sanic==0.5.4 +