Merge pull request #757 from monobot/asyncOrmV020
update asyncorm version example to 0.2.0
This commit is contained in:
commit
360adc9130
|
@ -16,8 +16,8 @@ app = Sanic(name=__name__)
|
||||||
def orm_configure(sanic, loop):
|
def orm_configure(sanic, loop):
|
||||||
db_config = {'database': 'sanic_example',
|
db_config = {'database': 'sanic_example',
|
||||||
'host': 'localhost',
|
'host': 'localhost',
|
||||||
'user': 'sanicdbuser',
|
'user': 'ormdbuser',
|
||||||
'password': 'sanicDbPass',
|
'password': 'ormDbPass',
|
||||||
}
|
}
|
||||||
|
|
||||||
# configure_orm needs a dictionary with:
|
# 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
|
# now the propper sanic workflow
|
||||||
class BooksView(HTTPMethodView):
|
class BooksView(HTTPMethodView):
|
||||||
|
|
||||||
|
@ -80,6 +89,7 @@ class BooksView(HTTPMethodView):
|
||||||
'results': BookSerializer.serialize(book),
|
'results': BookSerializer.serialize(book),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class BookView(HTTPMethodView):
|
class BookView(HTTPMethodView):
|
||||||
async def get_object(self, request, book_id):
|
async def get_object(self, request, book_id):
|
||||||
try:
|
try:
|
||||||
|
@ -136,4 +146,4 @@ app.add_route(BooksView.as_view(), '/books/')
|
||||||
app.add_route(BookView.as_view(), '/books/<book_id:int>/')
|
app.add_route(BookView.as_view(), '/books/<book_id:int>/')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run()
|
app.run(port=9000, debug=True)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from asyncorm.model import Model
|
from asyncorm import models
|
||||||
from asyncorm.fields import CharField, IntegerField, DateField
|
|
||||||
|
|
||||||
|
|
||||||
BOOK_CHOICES = (
|
BOOK_CHOICES = (
|
||||||
|
@ -9,13 +8,17 @@ BOOK_CHOICES = (
|
||||||
|
|
||||||
|
|
||||||
# This is a simple model definition
|
# This is a simple model definition
|
||||||
class Book(Model):
|
class Book(models.Model):
|
||||||
name = CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
synopsis = CharField(max_length=255)
|
synopsis = models.CharField(max_length=255)
|
||||||
book_type = CharField(max_length=15, null=True, choices=BOOK_CHOICES)
|
book_type = models.CharField(
|
||||||
pages = IntegerField(null=True)
|
max_length=15,
|
||||||
date_created = DateField(auto_now=True)
|
null=True,
|
||||||
|
choices=BOOK_CHOICES
|
||||||
|
)
|
||||||
|
pages = models.IntegerField(null=True)
|
||||||
|
date_created = models.DateField(auto_now=True)
|
||||||
|
|
||||||
class Meta():
|
class Meta():
|
||||||
ordering = ['name', ]
|
ordering = ['-name', ]
|
||||||
unique_together = ['name', 'synopsis']
|
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
|
from library.models import Book
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
asyncorm==0.0.9
|
asyncorm>=0.0.9
|
||||||
sanic==0.5.4
|
sanic==0.5.4
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user