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


Python models.SET_NULL属性代码示例

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


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

示例1: ask_remove_enum_values

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [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: test_on_delete_set_null_on_non_nullable_field

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

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

        field = Model._meta.get_field('foreign_key')
        self.assertEqual(field.check(), [
            Error(
                'Field specifies on_delete=SET_NULL, but cannot be null.',
                hint='Set null=True argument on the field, or change the on_delete rule.',
                obj=field,
                id='fields.E320',
            ),
        ]) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:test_relative_fields.py

示例3: test_to_fields_not_checked_if_related_model_doesnt_exist

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [as 别名]
def test_to_fields_not_checked_if_related_model_doesnt_exist(self):
        class Child(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()
            parent = ForeignObject(
                'invalid_models_tests.Parent',
                on_delete=models.SET_NULL,
                from_fields=('a', 'b'),
                to_fields=('a', 'b'),
            )

        field = Child._meta.get_field('parent')
        self.assertEqual(field.check(), [
            Error(
                "Field defines a relation with model 'invalid_models_tests.Parent', "
                "which is either not installed, or is abstract.",
                id='fields.E300',
                obj=field,
            ),
        ]) 
开发者ID:nesdis,项目名称:djongo,代码行数:22,代码来源:test_relative_fields.py

示例4: test_check_composite_foreign_object

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [as 别名]
def test_check_composite_foreign_object(self):
        class Parent(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()

            class Meta:
                unique_together = (('a', 'b'),)

        class Child(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()
            value = models.CharField(max_length=255)
            parent = ForeignObject(
                Parent,
                on_delete=models.SET_NULL,
                from_fields=('a', 'b'),
                to_fields=('a', 'b'),
                related_name='children',
            )

        self.assertEqual(Child._meta.get_field('parent').check(from_model=Child), []) 
开发者ID:nesdis,项目名称:djongo,代码行数:23,代码来源:tests.py

示例5: test_check_subset_composite_foreign_object

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [as 别名]
def test_check_subset_composite_foreign_object(self):
        class Parent(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()
            c = models.PositiveIntegerField()

            class Meta:
                unique_together = (('a', 'b'),)

        class Child(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()
            c = models.PositiveIntegerField()
            d = models.CharField(max_length=255)
            parent = ForeignObject(
                Parent,
                on_delete=models.SET_NULL,
                from_fields=('a', 'b', 'c'),
                to_fields=('a', 'b', 'c'),
                related_name='children',
            )

        self.assertEqual(Child._meta.get_field('parent').check(from_model=Child), []) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:tests.py

示例6: forwards

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [as 别名]
def forwards(self, orm):

        # Changing field 'Location.photo'
        db.alter_column(u'djangocms_gmaps_location', 'photo_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['filer.Image']))

        # Changing field 'Location.marker_icon'
        db.alter_column(u'djangocms_gmaps_location', 'marker_icon_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['filer.Image'])) 
开发者ID:mishbahr,项目名称:djangocms-gmaps,代码行数:9,代码来源:0002_auto__chg_field_location_photo__chg_field_location_marker_icon.py

示例7: backwards

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [as 别名]
def backwards(self, orm):
        # Adding model 'MaterialShapeNicenessLabel'
        db.create_table(u'shapes_materialshapenicenesslabel', (
            ('quality_method', self.gf('django.db.models.fields.CharField')(max_length=1, null=True, blank=True)),
            ('admin_score', self.gf('django.db.models.fields.IntegerField')(default=0)),
            ('time_active_ms', self.gf('django.db.models.fields.IntegerField')(blank=True, null=True, db_index=True)),
            ('canttell', self.gf('django.db.models.fields.NullBooleanField')(null=True, blank=True)),
            ('shape', self.gf('django.db.models.fields.related.ForeignKey')(related_name='nicenesses', to=orm['shapes.MaterialShape'])),
            ('added', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)),
            ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['accounts.UserProfile'])),
            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('mturk_assignment', self.gf('django.db.models.fields.related.ForeignKey')(related_name='+', null=True, to=orm['mturk.MtAssignment'], on_delete=models.SET_NULL, blank=True)),
            ('invalid', self.gf('django.db.models.fields.BooleanField')(default=False)),
            ('sandbox', self.gf('django.db.models.fields.BooleanField')(default=False)),
            ('time_ms', self.gf('django.db.models.fields.IntegerField')(blank=True, null=True, db_index=True)),
            ('reward', self.gf('django.db.models.fields.DecimalField')(null=True, max_digits=8, decimal_places=4, blank=True)),
            ('nice', self.gf('django.db.models.fields.BooleanField')(default=False)),
        ))
        db.send_create_signal(u'shapes', ['MaterialShapeNicenessLabel'])

        # Adding field 'MaterialShape.nice'
        db.add_column(u'shapes_materialshape', 'nice',
                      self.gf('django.db.models.fields.NullBooleanField')(null=True, blank=True),
                      keep_default=False)

        # Adding field 'MaterialShape.nice_score'
        db.add_column(u'shapes_materialshape', 'nice_score',
                      self.gf('django.db.models.fields.FloatField')(null=True, blank=True),
                      keep_default=False) 
开发者ID:seanbell,项目名称:opensurfaces,代码行数:31,代码来源:0002_auto__del_materialshapenicenesslabel__del_field_materialshape_nice__de.py

示例8: __init__

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [as 别名]
def __init__(self, **kwargs):
        kwargs["to"] = "files.File"
        kwargs["on_delete"] = models.SET_NULL
        kwargs["null"] = True
        super().__init__(**kwargs) 
开发者ID:webkom,项目名称:lego,代码行数:7,代码来源:models.py

示例9: test_post_redirect_page

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [as 别名]
def test_post_redirect_page(self):
        field = self.get_field(Form, "post_redirect_page")
        self.assertModelPKField(field, Page, models.SET_NULL, True, True) 
开发者ID:labd,项目名称:wagtailstreamforms,代码行数:5,代码来源:test_form.py

示例10: __init__

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [as 别名]
def __init__(self, *args, **kwargs):
        defaults = {
            'verbose_name': _('Category'),
            'to': Category,
            'on_delete': models.SET_NULL,
            'null': True,
            'blank': True,
            'related_name': '+',
        }
        defaults.update(kwargs)
        super().__init__(**defaults) 
开发者ID:liqd,项目名称:adhocracy4,代码行数:13,代码来源:fields.py

示例11: test_serialize_functions

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [as 别名]
def test_serialize_functions(self):
        with self.assertRaisesMessage(ValueError, 'Cannot serialize function: lambda'):
            self.assertSerializedEqual(lambda x: 42)
        self.assertSerializedEqual(models.SET_NULL)
        string, imports = MigrationWriter.serialize(models.SET(42))
        self.assertEqual(string, 'models.SET(42)')
        self.serialize_round_trip(models.SET(42)) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:9,代码来源:test_writer.py

示例12: test_to_fields_exist

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

        class Child(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()
            parent = ForeignObject(
                Parent,
                on_delete=models.SET_NULL,
                from_fields=('a', 'b'),
                to_fields=('a', 'b'),
            )

        field = Child._meta.get_field('parent')
        self.assertEqual(field.check(), [
            Error(
                "The to_field 'a' doesn't exist on the related model 'invalid_models_tests.Parent'.",
                obj=field,
                id='fields.E312',
            ),
            Error(
                "The to_field 'b' doesn't exist on the related model 'invalid_models_tests.Parent'.",
                obj=field,
                id='fields.E312',
            ),
        ]) 
开发者ID:nesdis,项目名称:djongo,代码行数:29,代码来源:test_relative_fields.py

示例13: test_superset_foreign_object

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [as 别名]
def test_superset_foreign_object(self):
        class Parent(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()
            c = models.PositiveIntegerField()

            class Meta:
                unique_together = (('a', 'b', 'c'),)

        class Child(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()
            value = models.CharField(max_length=255)
            parent = ForeignObject(
                Parent,
                on_delete=models.SET_NULL,
                from_fields=('a', 'b'),
                to_fields=('a', 'b'),
                related_name='children',
            )

        field = Child._meta.get_field('parent')
        self.assertEqual(field.check(from_model=Child), [
            Error(
                "No subset of the fields 'a', 'b' on model 'Parent' is unique.",
                hint=(
                    "Add unique=True on any of those fields or add at least "
                    "a subset of them to a unique_together constraint."
                ),
                obj=field,
                id='fields.E310',
            ),
        ]) 
开发者ID:nesdis,项目名称:djongo,代码行数:35,代码来源:test_relative_fields.py

示例14: test_intersection_foreign_object

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [as 别名]
def test_intersection_foreign_object(self):
        class Parent(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()
            c = models.PositiveIntegerField()
            d = models.PositiveIntegerField()

            class Meta:
                unique_together = (('a', 'b', 'c'),)

        class Child(models.Model):
            a = models.PositiveIntegerField()
            b = models.PositiveIntegerField()
            d = models.PositiveIntegerField()
            value = models.CharField(max_length=255)
            parent = ForeignObject(
                Parent,
                on_delete=models.SET_NULL,
                from_fields=('a', 'b', 'd'),
                to_fields=('a', 'b', 'd'),
                related_name='children',
            )

        field = Child._meta.get_field('parent')
        self.assertEqual(field.check(from_model=Child), [
            Error(
                "No subset of the fields 'a', 'b', 'd' on model 'Parent' is unique.",
                hint=(
                    "Add unique=True on any of those fields or add at least "
                    "a subset of them to a unique_together constraint."
                ),
                obj=field,
                id='fields.E310',
            ),
        ]) 
开发者ID:nesdis,项目名称:djongo,代码行数:37,代码来源:test_relative_fields.py

示例15: media_consumi

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import SET_NULL [as 别名]
def media_consumi(self):
        rifornimenti = Rifornimento.objects.filter(veicolo=self)
        litri = 0
        for rifornimento in rifornimenti:
            litri += rifornimento.consumo_carburante
        try:
            ultimo_rifornimento = Rifornimento.objects.filter(veicolo=self).latest("data")
            primo_rifornimento = Rifornimento.objects.filter(veicolo=self).earliest("data")
        except Rifornimento.DoesNotExist:
            return 0
        km = ultimo_rifornimento.contachilometri - primo_rifornimento.contachilometri
        litri -= ultimo_rifornimento.consumo_carburante
        if litri != 0:
            return round(km/litri, 2)
        else:
            return 0

# class Immatricolazione(ModelloSemplice, ConMarcaTemporale):
#     """
#     Rappresenta una pratica di immatricolazione di un Veicolo
#
#     Una pratica viene istruita da un ufficio motorizzazione per conto di una unita' CRI richiedente.
#     La stessa viene sottoposta a due stadi di approvazione, in seguito alla istruzione. Quando la
#     pratica termina, il veicolo viene immatricolato ed entra in servizio.
#     """
#
#     class Meta:
#         verbose_name = "Pratica di Immatricolazione"
#         verbose_name_plural = "Pratiche di Immatricolazione"
#
#     richiedente = models.ForeignKey(Sede, related_name='immatricolazioni_richieste', null=True, on_delete=models.SET_NULL)
#     ufficio = models.ForeignKey(Sede, related_name='immatricolazioni_istruite', on_delete=models.PROTECT)
#     veicolo = models.ForeignKey(Veicolo, related_name='richieste_immatricolazione', on_delete=models.CASCADE) 
开发者ID:CroceRossaItaliana,项目名称:jorvik,代码行数:35,代码来源:models.py


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