本文整理匯總了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
示例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'])
示例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',
),
])