Thank You! And I found how to do that I want. I added support of 'native postgres inheritance' into web2py:
~/web2py/gluon/packages/dal/pydal/git diff
diff --git a/pydal/adapters/base.py b/pydal/adapters/base.py
index 94c6819..9ddfaad 100644
--- a/pydal/adapters/base.py
+++ b/pydal/adapters/base.py
@@ -417,11 +417,17 @@ class BaseAdapter(with_metaclass(AdapterMeta, ConnectionPool)):
sql_fields_aux[field_name] = dict(sql=ftype)
# Postgres - PostGIS:
# geometry fields are added after the table has been created, not now
+ if field_name in table.inherit_fields:
+ continue
if not (self.dbengine == 'postgres' and \
field_type.startswith('geom')):
fields.append('%s %s' % (field.sqlsafe_name, ftype))
other = ';'
+ if table.inherit_tables:
+ other = 'INHERITS (%s);' % ','.join(self.QUOTE_TEMPLATE % inherit_table for inherit_table in table.inherit_tables)
+ fields.append('PRIMARY KEY (%s)' % (self.QUOTE_TEMPLATE % table._
id.name))
+
# backend-specific extensions to fields
if self.dbengine == 'mysql':
if not hasattr(table, "_primarykey"):
diff --git a/pydal/objects.py b/pydal/objects.py
index e63eaab..f0adb29 100644
--- a/pydal/objects.py
+++ b/pydal/objects.py
@@ -278,6 +278,8 @@ class Table(Serializable, BasicStorage):
if field.type == 'id':
self._id = field
+ self.inherit_tables = []
+ self.inherit_fields = []
for field in fields:
if isinstance(field, (FieldVirtual, FieldMethod)):
virtual_fields.append(field)
@@ -287,10 +289,13 @@ class Table(Serializable, BasicStorage):
include_new(field)
elif isinstance(field, Table):
table = field
+ self.inherit_tables.append(table._tablename)
+ self.inherit_fields.append('id')
for field in table:
if
field.name not in fieldnames and field.type != 'id':
t2 = not table._actual and self._tablename
include_new(field.clone(point_self_references_to=t2))
elif isinstance(field, dict) and field['fieldname'] not in fieldnames:
include_new(Field(**field))
elif not isinstance(field, (Field, Table)):
четверг, 28 января 2016 г., 4:24:24 UTC+5 пользователь Massimo Di Pierro написал: