root / elixir / trunk / elixir / properties.py @ 132

Revision 132, 1.0 kB (checked in by ged, 7 years ago)

aaah, the joy of forgetting to commit a file

Line 
1'''
2Special properties statements for Elixir entities
3
4==========
5Properties
6==========
7
8This module contains DSL statements which allow you to declare special
9properties your Elixir entities might have.  For simple fields or relation
10between your entities, please the corresponding modules.
11
12`has_property`
13--------------
14The `has_property` statement allows you to define properties which rely on
15their entity's table and columns (an thus which need them to be defined before
16the property can be declared).
17
18Here is a quick example of how to use ``has_property``.
19
20::
21
22    class OrderLine(Entity):
23        has_field('quantity', Float)
24        has_field('unit_price', Float)
25        has_property('price',
26                     lambda c: column_property(
27                         (c.quantity * c.unit_price).label('price')))
28'''
29
30from elixir.statements import Statement
31
32class HasProperty(object):
33
34    def __init__(self, entity, name, prop):
35        entity._descriptor.add_property(name, prop)
36
37
38has_property = Statement(HasProperty)
Note: See TracBrowser for help on using the browser.