|
Revision 132, 1.0 kB
(checked in by ged, 6 years ago)
|
|
aaah, the joy of forgetting to commit a file
|
| Line | |
|---|
| 1 | ''' |
|---|
| 2 | Special properties statements for Elixir entities |
|---|
| 3 | |
|---|
| 4 | ========== |
|---|
| 5 | Properties |
|---|
| 6 | ========== |
|---|
| 7 | |
|---|
| 8 | This module contains DSL statements which allow you to declare special |
|---|
| 9 | properties your Elixir entities might have. For simple fields or relation |
|---|
| 10 | between your entities, please the corresponding modules. |
|---|
| 11 | |
|---|
| 12 | `has_property` |
|---|
| 13 | -------------- |
|---|
| 14 | The `has_property` statement allows you to define properties which rely on |
|---|
| 15 | their entity's table and columns (an thus which need them to be defined before |
|---|
| 16 | the property can be declared). |
|---|
| 17 | |
|---|
| 18 | Here 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 | |
|---|
| 30 | from elixir.statements import Statement |
|---|
| 31 | |
|---|
| 32 | class HasProperty(object): |
|---|
| 33 | |
|---|
| 34 | def __init__(self, entity, name, prop): |
|---|
| 35 | entity._descriptor.add_property(name, prop) |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | has_property = Statement(HasProperty) |
|---|