當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。