Python django.db.models 模块,SubfieldBase() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用django.db.models.SubfieldBase()

项目:dj-txmoney    作者:txerpa    | 项目源码 | 文件源码
def contribute_to_class(self, cls, name):
        self.name = name
        self.amount_field_name = name
        self.currency_field_name = currency_field_name(name)

        if not cls._meta.abstract:
            c_field = CurrencyField(
                max_length=3,
                default=self.default_currency,
                editable=False,
                null=False,  # empty char fields should be ''
                blank=self.blankable,
                db_column=currency_field_db_column(self.db_column),
            )
            # Use this field's creation counter for the currency field. This
            # field will get a +1 when we call super
            c_field.creation_counter = self.creation_counter
            cls.add_to_class(self.currency_field_name, c_field)

        # Set ourselves up normally
        super(MoneyField, self).contribute_to_class(cls, name)

        # As we are not using SubfieldBase, we need to set our proxy class here
        setattr(cls, self.name, MoneyFieldProxy(self))

        # Set our custom manager
        if not hasattr(cls, '_default_manager'):
            cls.add_to_class('objects', MoneyManager())
项目:mes    作者:osess    | 项目源码 | 文件源码
def _get_subfield_superclass():
    # hardcore trick to support django < 1.3 - there was something wrong with
    # inheritance and SubfieldBase before django 1.3
    # see https://github.com/django/django/commit/222c73261650201f5ce99e8dd4b1ce0d30a69eb4
    if django.VERSION < (1,3):
        return models.Field
    return six.with_metaclass(models.SubfieldBase, models.Field)