update asyncorm version example to 0.2.0
This commit is contained in:
parent
21aa3f6578
commit
9a27555763
|
@ -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/<book_id:int>/')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
app.run(port=9000, debug=True)
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from asyncorm.model import ModelSerializer, SerializerMethod
|
||||
from asyncorm.serializers import ModelSerializer, SerializerMethod
|
||||
from library.models import Book
|
||||
|
||||
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
asyncorm==0.0.9
|
||||
asyncorm>=0.0.9
|
||||
sanic==0.5.4
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user