Merge pull request #757 from monobot/asyncOrmV020

update asyncorm version example to 0.2.0
This commit is contained in:
Raphael Deem 2017-05-29 22:51:46 -07:00 committed by GitHub
commit 360adc9130
4 changed files with 28 additions and 14 deletions

View File

@ -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)

View File

@ -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']

View File

@ -1,4 +1,4 @@
from asyncorm.model import ModelSerializer, SerializerMethod
from asyncorm.serializers import ModelSerializer, SerializerMethod
from library.models import Book

View File

@ -1,2 +1,3 @@
asyncorm==0.0.9
asyncorm>=0.0.9
sanic==0.5.4