当前位置: 首页>>代码示例>>Python>>正文


Python models.SET_DEFAULT属性代码示例

本文整理汇总了Python中django.db.models.SET_DEFAULT属性的典型用法代码示例。如果您正苦于以下问题:Python models.SET_DEFAULT属性的具体用法?Python models.SET_DEFAULT怎么用?Python models.SET_DEFAULT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在django.db.models的用法示例。


在下文中一共展示了models.SET_DEFAULT属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ask_remove_enum_values

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_DEFAULT [as 别名]
def ask_remove_enum_values(self, db_type, values):
        """ How to treat records with deleted enum values. """
        # Ordered ensures
        choices = [
            (models.CASCADE, "Cascade - Delete records with removed values"),
            (models.PROTECT, "Protect - Block migrations if records contain removed values"),
            (models.SET_NULL, "Set NULL - Set value to NULL"),
            (models.SET_DEFAULT, "Set default - Set value to field default"),
            (models.SET, "Set value - Provide a one off default now"),
            (models.DO_NOTHING, "Do nothing - Consistency must be handled elsewhere"),
            (None, "Leave it to field definitions")]
        choice, _ = choices[self._choice_input(
            "Enum {db_type} has had {values} removed, "
            "existing records may need to be updated. "
            "Override update behaviour or do nothing and follow field behaviour.".format(
                db_type=db_type,
                values=values),
            [q for (k, q) in choices]) - 1]
        if choice == models.SET:
            return models.SET(self._ask_default())
        return choice 
开发者ID:ashleywaite,项目名称:django-more,代码行数:23,代码来源:patches.py

示例2: forwards

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_DEFAULT [as 别名]
def forwards(self, orm):
        # Adding model 'HTKShortUrl'
        db.create_table(u'htk_htkshorturl', (
            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('url', self.gf('django.db.models.fields.CharField')(max_length=256)),
            ('creator', self.gf('django.db.models.fields.related.ForeignKey')(related_name='short_urls', on_delete=models.SET_DEFAULT, default=None, to=orm['auth.User'], blank=True, null=True)),
            ('created_on', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime(2015, 2, 21, 0, 0), auto_now_add=True, blank=True)),
        ))
        db.send_create_signal('htk', ['HTKShortUrl'])

        # Adding model 'HTKShortUrlAccess'
        db.create_table(u'htk_htkshorturlaccess', (
            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('url', self.gf('django.db.models.fields.related.ForeignKey')(related_name='accesses', to=orm['htk.HTKShortUrl'])),
            ('timestamp', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
            ('user', self.gf('django.db.models.fields.related.ForeignKey')(default=None, to=orm['auth.User'], null=True, on_delete=models.SET_DEFAULT, blank=True)),
            ('user_agent', self.gf('django.db.models.fields.CharField')(max_length=256, blank=True)),
            ('user_ip', self.gf('django.db.models.fields.CharField')(max_length=15, blank=True)),
            ('referrer', self.gf('django.db.models.fields.CharField')(max_length=256, blank=True)),
        ))
        db.send_create_signal('htk', ['HTKShortUrlAccess']) 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:23,代码来源:0003_auto__add_htkshorturl__add_htkshorturlaccess.py

示例3: test_on_delete_set_default_without_default_value

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_DEFAULT [as 别名]
def test_on_delete_set_default_without_default_value(self):
        class Person(models.Model):
            pass

        class Model(models.Model):
            foreign_key = models.ForeignKey('Person', models.SET_DEFAULT)

        field = Model._meta.get_field('foreign_key')
        self.assertEqual(field.check(), [
            Error(
                'Field specifies on_delete=SET_DEFAULT, but has no default value.',
                hint='Set a default value, or change the on_delete rule.',
                obj=field,
                id='fields.E321',
            ),
        ]) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:test_relative_fields.py


注:本文中的django.db.models.SET_DEFAULT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。