當前位置: 首頁>>代碼示例>>Python>>正文


Python models.DO_NOTHING屬性代碼示例

本文整理匯總了Python中django.db.models.DO_NOTHING屬性的典型用法代碼示例。如果您正苦於以下問題:Python models.DO_NOTHING屬性的具體用法?Python models.DO_NOTHING怎麽用?Python models.DO_NOTHING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.db.models的用法示例。


在下文中一共展示了models.DO_NOTHING屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ask_remove_enum_values

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import DO_NOTHING [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: __init__

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import DO_NOTHING [as 別名]
def __init__(self, to, *args, **kwargs):
        self.to = to
        if (isinstance(to,basestring)):
            super(JeevesForeignKey, self).__init__(
                    to, kwargs.pop("on_delete",models.DO_NOTHING), kwargs.pop("from_fields",[]), kwargs.pop("to_fields",[]), *args, **kwargs)
        else:
            self.join_field = to._meta.pk
            for field in to._meta.fields:
                if field.name == 'jeeves_id':
                    self.join_field = field
                    break
                else:
                    # support non-Jeeves tables
                    self.join_field = to._meta.pk
                    #raise Exception("Need jeeves_id field")

            super(JeevesForeignKey, self).__init__(
                    to, models.DO_NOTHING, [self], [self.join_field], *args, **kwargs)
        self.db_constraint = False 
開發者ID:jeanqasaur,項目名稱:jeeves,代碼行數:21,代碼來源:JeevesModel.py

示例3: __init__

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import DO_NOTHING [as 別名]
def __init__(self, to, on_delete=models.DO_NOTHING, related_name=None, related_query_name=None,
                 limit_choices_to=None, parent_link=False, to_field=None, db_constraint=False,  **kwargs):
        super(ForeignKey, self).__init__(to, on_delete, related_name, related_query_name, limit_choices_to,
                                         parent_link, to_field, db_constraint, **kwargs) 
開發者ID:007gzs,項目名稱:dingtalk-django-example,代碼行數:6,代碼來源:model.py

示例4: test_do_nothing

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import DO_NOTHING [as 別名]
def test_do_nothing(self):
        # Testing DO_NOTHING is a bit harder: It would raise IntegrityError for a normal model,
        # so we connect to pre_delete and set the fk to a known value.
        replacement_r = R.objects.create()

        def check_do_nothing(sender, **kwargs):
            obj = kwargs['instance']
            obj.donothing_set.update(donothing=replacement_r)
        models.signals.pre_delete.connect(check_do_nothing)
        a = create_a('do_nothing')
        a.donothing.delete()
        a = A.objects.get(pk=a.pk)
        self.assertEqual(replacement_r, a.donothing)
        models.signals.pre_delete.disconnect(check_do_nothing) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:16,代碼來源:tests.py

示例5: __init__

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import DO_NOTHING [as 別名]
def __init__(self, *args, **kwargs):
        kwargs['on_delete'] = models.DO_NOTHING
        super().__init__(*args, **kwargs) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:5,代碼來源:empty_join.py

示例6: __init__

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import DO_NOTHING [as 別名]
def __init__(self, field, to, related_name=None, limit_choices_to=None, related_query_name=None):
        super(GenericRel, self).__init__(field=field, to=to, related_name=related_query_name or '+',
                                         limit_choices_to=limit_choices_to, on_delete=DO_NOTHING,
                                         related_query_name=related_query_name) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:6,代碼來源:fields.py

示例7: __init__

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import DO_NOTHING [as 別名]
def __init__(self, verbose_name=None, choices=None, to_field=None, **kwargs):
        self.suggestions_source_field = to_field
        self.suggestions = choices
        kwargs.update(
            db_constraint=False, null=True, on_delete=models.DO_NOTHING,
            to=self.suggestions, to_field=to_field, verbose_name=verbose_name)
        super().__init__(**kwargs) 
開發者ID:tejoesperanto,項目名稱:pasportaservo,代碼行數:9,代碼來源:fields.py

示例8: __init__

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import DO_NOTHING [as 別名]
def __init__(self, field, to, related_name=None, related_query_name=None, limit_choices_to=None):
        super(GenericRel, self).__init__(
            field, to,
            related_name=related_query_name or '+',
            related_query_name=related_query_name,
            limit_choices_to=limit_choices_to,
            on_delete=DO_NOTHING,
        ) 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:10,代碼來源:fields.py

示例9: test_do_nothing_qscount

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import DO_NOTHING [as 別名]
def test_do_nothing_qscount(self):
        """
        A models.DO_NOTHING relation doesn't trigger a query.
        """
        b = Base.objects.create()
        with self.assertNumQueries(1):
            # RelToBase should not be queried.
            b.delete()
        self.assertEqual(Base.objects.count(), 0) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:tests.py


注:本文中的django.db.models.DO_NOTHING屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。