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):
fieldnames.add(field.name)
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))
+ self.inherit_fields.append(field.name)
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
написал:
>
> db.define_table('abonent', Field('a'))
> db.define_table('person', db.abonet, Field('b')) # has a,b
> db.define_table('company', db.abonet, Field('c')) # has a,c
> db.define_table('provider', db.company, Field('d')) # has a,c,d
>
>
> On Wednesday, 27 January 2016 17:05:57 UTC-6, RekGRpth wrote:
>>
>> I have 4 classes: Abonent, Person, Company and Provider.
>> Person and Company are (sublasses of) Abonents, and Provider is
>> (subclasses of) Company.
>> In django I can write
>>
>> class Abonent(models.Model): passclass Person(Abonent): passclass
>> Company(Abonent): passclass Provider(Company): pass
>>
>> how it will be in web2py?
>> follow does not works:
>>
>> db.define_table('abonent')
>> db.define_table('person', Field('abonent', db.abonent),
>> primarykey=['abonent'])
>> db.define_table('company', Field('abonent', db.abonent),
>> primarykey=['abonent'])
>> db.define_table('provider', Field('company', db.company),
>> primarykey=['company'])
>>
>> and this
>>
>> db.define_table('abonent')
>> db.define_table('person', Field('abonent', db.abonent),
>> primarykey=['abonent'])
>> db.define_table('company', Field('abonent', db.abonent),
>> primarykey=['abonent'])
>> db.define_table('provider', Field('company', db.company.abonent),
>> primarykey=['company'])
>>
>> and this
>>
>> db.define_table('abonent')
>> db.define_table('person', Field('abonent', type='reference abonent'),
>> primarykey=['abonent'])
>> db.define_table('company', Field('abonent', type='reference abonent'),
>> primarykey=['abonent'])
>> db.define_table('provider', Field('company', type='reference
>> company.abonent'), primarykey=['company'])
>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.