Add support for domain_<field name> method
issue4126 review6501002
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Add support for domain_<field name> method
|
||||
* Refactor configuration file and command line
|
||||
* Use the context of the relation field for instanciation
|
||||
* Use a configuration field for logging
|
||||
|
||||
@@ -188,6 +188,18 @@ Default value
|
||||
|
||||
See :ref:`default value <topics-fields_default_value>`
|
||||
|
||||
Searching
|
||||
=========
|
||||
|
||||
A class method could be defined for each field which must return a SQL
|
||||
expression for the given domain instead of the default one.
|
||||
The method signature is::
|
||||
|
||||
domain_<field name>(domain, tables)
|
||||
|
||||
Where ``domain`` is the simple :ref:`domain <topics-domain>` clause and
|
||||
``tables`` is a nested dictionary, see :meth:`~Field.convert_domain`.
|
||||
|
||||
Ordering
|
||||
========
|
||||
|
||||
|
||||
@@ -251,6 +251,9 @@ class Field(object):
|
||||
table, _ = tables[None]
|
||||
name, operator, value = domain
|
||||
assert name == self.name
|
||||
method = getattr(Model, 'domain_%s' % name, None)
|
||||
if method:
|
||||
return method(domain, tables)
|
||||
Operator = SQL_OPERATORS[operator]
|
||||
column = self.sql_column(table)
|
||||
expression = Operator(column, self._domain_value(operator, value))
|
||||
|
||||
Reference in New Issue
Block a user