将Architect与Django抽象模型类结合使用

时间:2019-03-18 10:04:07

标签: python django django-models python-architect

PyPI Architect指定,对于分区,我们可以通过以下方式在任何模型类上使用装饰器:

import architect

@architect.install('partition', **options)
class Model(object):
    pass

我的模型是抽象的,要分区的列在抽象模型中,我希望所有子模型都具有相同的分区。

import architect

@architect.install('partition', **options)
class Model(object):
    class Meta:
        abstract = True
  • 以上结构使用正确吗?
  • 所有子模型会自动实现相同的分区吗?
  • 如果,在抽象级别指定装饰器是否安全(良好做法)?

Django:2.x || Python:3.x || MySQL:5.x

1 个答案:

答案 0 :(得分:2)

我自己还没有在抽象模型上使用python-archtitect,但是在其源代码中发现了像this这样的注释,它至少旨在与各种继承一起使用。

装饰器主要向类添加一个属性作为描述符,该类提供对所有功能的访问:$ dpkg -l | grep ssl ii libgnutls-openssl27:amd64 3.3.30-0+deb8u1 amd64 GNU TLS library - OpenSSL wrapper ii libio-socket-ssl-perl 2.002-2+deb8u3 all Perl module implementing object oriented interface to SSL sockets ii libnet-smtp-ssl-perl 1.01-3 all Perl module providing SSL support to Net::SMTP ii libnet-ssleay-perl 1.65-1+deb8u1 amd64 Perl module for Secure Sockets Layer (SSL) ii libssl-doc 1.0.1t-1+deb8u11 all Secure Sockets Layer toolkit - development documentation ii libssl1.0.0:amd64 1.0.1t-1+deb8u11 amd64 Secure Sockets Layer toolkit - shared libraries ii openssl 1.0.1t-1+deb8u11 amd64 Secure Sockets Layer toolkit - cryptographic utility ii python-openssl 0.14-1 all Python 2 wrapper around the OpenSSL library ii ssl-cert 1.0.35 all simple debconf wrapper for OpenSSL 。通常,这不应干扰任何类型的类继承。