From eb1582bdfc6e6a7ebe87c07b22c998a981ef1432 Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Wed, 23 Oct 2013 15:37:51 +0300 Subject: [PATCH] Added one more example for generates --- docs/index.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 08c7f1f..56f7485 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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 --------------------