Added one more example for generates

This commit is contained in:
Konsta Vesterinen
2013-10-23 15:37:51 +03:00
parent 002b5b69cd
commit eb1582bdfc

View File

@@ -248,7 +248,7 @@ TimezoneType saves timezone objects as strings on the way in and converts them b
The generates decorator
-----------------------
Many times you may have properties which values are being generated. Usual cases include slugs from names or resized thumbnails from images.
Many times you may have generated property values. Usual cases include slugs from names or resized thumbnails from images.
SQLAlchemy-Utils provides a way to do this easily with `generates` decorator:
@@ -302,6 +302,16 @@ These property generators can even be defined outside classes:
return self.name.lower().replace(' ', '-')
Or with lazy evaluated string argument:
::
@generates('Article.slug')
def _create_article_slug(self):
return self.name.lower().replace(' ', '-')
Generic Relationship
--------------------