Python django.db.models 模块,SET_NULL 实例源码

我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用django.db.models.SET_NULL

项目:a4-opin    作者:liqd    | 项目源码 | 文件源码
def __new__(cls, name, bases, namespace):
        panels = namespace['panels']
        blueprint_names = namespace['blueprint_names']

        for member in blueprint_names:
            namespace[member.name] = models.ForeignKey(
                'a4projects.Project',
                on_delete=models.SET_NULL,
                null=True,
                blank=True,
                related_name='example_project_{}'.format(member.name),
                help_text='Please select an exemplary {} project.'.format(
                    member.value
                ),
            )
            panels += [edit_handlers.FieldPanel(member.name)]
        return super().__new__(cls, name, bases, namespace)
项目:ecs_sclm    作者:meaningful    | 项目源码 | 文件源码
def forwards(self, orm):

        # Changing field 'File.owner'
        db.alter_column(u'filer_file', 'owner_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['auth.User']))

        # Changing field 'Folder.owner'
        db.alter_column(u'filer_folder', 'owner_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['auth.User']))

        # Changing field 'FolderPermission.user'
        db.alter_column(u'filer_folderpermission', 'user_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['auth.User']))
项目:Hoshimori_Project    作者:kokonguyen191    | 项目源码 | 文件源码
def http_skill_preview_url(self):
        return get_http_image_url_from_path(self.skill_preview)

    # action_skill = models.OneToOne('ActionSkill', verbose_name=_('Action Skill'), related_name='skill', null=True,
    #                                  on_delete=models.SET_NULL)
    # evolved_action_skill = models.OneToOne('ActionSkill', verbose_name=_('Evolved Action Skill'),
    #                                          related_name='evolved skill', null=True, on_delete=models.SET_NULL)
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        kwargs.setdefault('on_delete', models.SET_NULL)
        super().__init__(*args, **kwargs)
项目:django_wagtail_boilerplate    作者:AccentDesign    | 项目源码 | 文件源码
def test_user(self):
        field = ServeLog._meta.get_field('user')
        self.assertModelPKField(field, User, models.SET_NULL, True, False)
项目:django_wagtail_boilerplate    作者:AccentDesign    | 项目源码 | 文件源码
def test_image(self):
        field = AbstractCard._meta.get_field('image')
        self.assertModelPKField(field, 'wagtailimages.Image', models.SET_NULL, True, True)
项目:django_wagtail_boilerplate    作者:AccentDesign    | 项目源码 | 文件源码
def test_feed_image(self):
        field = BasicPage._meta.get_field('feed_image')
        self.assertModelPKField(field, Image, models.SET_NULL, True, True)

    # properties
项目:django_wagtail_boilerplate    作者:AccentDesign    | 项目源码 | 文件源码
def test_link_page(self):
        field = AbstractLinkFields._meta.get_field('link_page')
        self.assertModelPKField(field, 'wagtailcore.Page', models.SET_NULL, True, True)
项目:django_wagtail_boilerplate    作者:AccentDesign    | 项目源码 | 文件源码
def test_link_document(self):
        field = AbstractLinkFields._meta.get_field('link_document')
        self.assertModelPKField(field, 'wagtaildocs.Document', models.SET_NULL, True, True)
项目:jiango    作者:yefei    | 项目源码 | 文件源码
def user_pre_delete(instance, **kwargs):
    # ??? ForeignKey(on_delete=models.SET_NULL) ???? Log.user ????
    Log.objects.filter(user=instance).update(user=None)
项目:gougo    作者:amaozhao    | 项目源码 | 文件源码
def forwards(self, orm):

        # Changing field 'File.owner'
        db.alter_column(u'filer_file', 'owner_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['auth.User']))

        # Changing field 'Folder.owner'
        db.alter_column(u'filer_folder', 'owner_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['auth.User']))

        # Changing field 'FolderPermission.user'
        db.alter_column(u'filer_folderpermission', 'user_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['auth.User']))
项目:adhocracy4    作者:liqd    | 项目源码 | 文件源码
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)
项目:alterchef    作者:libremesh    | 项目源码 | 文件源码
def forwards(self, orm):
        # Adding model 'Network'
        db.create_table('firmcreator_network', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
            ('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=100)),
            ('slug', self.gf('autoslug.fields.AutoSlugField')(unique_with=(), max_length=50, populate_from='name', blank=True)),
            ('description', self.gf('django.db.models.fields.TextField')()),
        ))
        db.send_create_signal('firmcreator', ['Network'])

        # Adding model 'FwProfile'
        db.create_table('firmcreator_fwprofile', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('network', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['firmcreator.Network'])),
            ('name', self.gf('django.db.models.fields.SlugField')(default='default', max_length=15)),
            ('slug', self.gf('autoslug.fields.AutoSlugField')(unique_with=(), max_length=50, populate_from=None)),
            ('description', self.gf('django.db.models.fields.TextField')()),
            ('creation_date', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)),
            ('path', self.gf('django.db.models.fields.CharField')(max_length=255)),
            ('based_on', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['firmcreator.FwProfile'], null=True, on_delete=models.SET_NULL, blank=True)),
            ('include_packages', self.gf('django.db.models.fields.TextField')(blank=True)),
            ('include_files', self.gf('altermeshfc.firmcreator.fields.JSONField')(default='{}')),
        ))
        db.send_create_signal('firmcreator', ['FwProfile'])

        # Adding unique constraint on 'FwProfile', fields ['network', 'name']
        db.create_unique('firmcreator_fwprofile', ['network_id', 'name'])

        # Adding model 'FwJob'
        db.create_table('firmcreator_fwjob', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('status', self.gf('django.db.models.fields.CharField')(default='WAITING', max_length=10)),
            ('profile', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['firmcreator.FwProfile'])),
            ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
            ('job_data', self.gf('altermeshfc.firmcreator.fields.JSONField')(default='{}')),
        ))
        db.send_create_signal('firmcreator', ['FwJob'])
项目:maas    作者:maas    | 项目源码 | 文件源码
def forwards(self, orm):
        # Adding field 'Node.boot_interface'
        db.add_column('maasserver_node', 'boot_interface',
                      self.gf('django.db.models.fields.related.ForeignKey')(related_name='+', on_delete=models.SET_NULL, default=None, to=orm['maasserver.Interface'], blank=True, null=True),
                      keep_default=False)

        # Adding field 'Interface.node'
        db.add_column('maasserver_interface', 'node',
                      self.gf('django.db.models.fields.related.ForeignKey')(to=orm['maasserver.Node'], null=True, blank=True),
                      keep_default=False)

        # Adding field 'Interface.mac_address'
        db.add_column('maasserver_interface', 'mac_address',
                      self.gf('maasserver.fields.MACAddressField')(null=True, blank=True),
                      keep_default=False)
项目:maas    作者:maas    | 项目源码 | 文件源码
def backwards(self, orm):
        # Adding field 'Node.pxe_mac'
        db.add_column('maasserver_node', 'pxe_mac',
                      self.gf('django.db.models.fields.related.ForeignKey')(related_name='+', on_delete=models.SET_NULL, default=None, to=orm['maasserver.MACAddress'], blank=True, null=True),
                      keep_default=False)

        # Adding field 'Interface.mac'
        db.add_column('maasserver_interface', 'mac',
                      self.gf('django.db.models.fields.related.ForeignKey')(to=orm['maasserver.MACAddress'], null=True, blank=True),
                      keep_default=False)

        # Add the unique constraint for mac_id.
        db.execute(
            "CREATE UNIQUE INDEX maasserver_interface_mac_id_name_idx ON "
            "maasserver_interface (mac_id, name) WHERE mac_id IS NOT NULL")
项目:maas    作者:maas    | 项目源码 | 文件源码
def forwards(self, orm):
        # Adding field 'Node.gateway_link_ipv4'
        db.add_column('maasserver_node', 'gateway_link_ipv4',
                      self.gf('django.db.models.fields.related.ForeignKey')(related_name='+', on_delete=models.SET_NULL, default=None, to=orm['maasserver.StaticIPAddress'], blank=True, null=True),
                      keep_default=False)

        # Adding field 'Node.gateway_link_ipv6'
        db.add_column('maasserver_node', 'gateway_link_ipv6',
                      self.gf('django.db.models.fields.related.ForeignKey')(related_name='+', on_delete=models.SET_NULL, default=None, to=orm['maasserver.StaticIPAddress'], blank=True, null=True),
                      keep_default=False)
项目:maas    作者:maas    | 项目源码 | 文件源码
def backwards(self, orm):
        # Adding model 'Network'
        db.create_table('maasserver_network', (
            ('dns_servers', self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True)),
            ('netmask', self.gf('maasserver.fields.MAASIPAddressField')(max_length=39)),
            ('description', self.gf('django.db.models.fields.TextField')(blank=True)),
            ('default_gateway', self.gf('maasserver.fields.MAASIPAddressField')(max_length=39, null=True, blank=True)),
            ('ip', self.gf('maasserver.fields.MAASIPAddressField')(max_length=39, unique=True)),
            ('vlan_tag', self.gf('django.db.models.fields.PositiveSmallIntegerField')(unique=True, null=True, blank=True)),
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('name', self.gf('django.db.models.fields.CharField')(max_length=255, unique=True)),
        ))
        db.send_create_signal('maasserver', ['Network'])

        # Adding model 'DHCPLease'
        db.create_table('maasserver_dhcplease', (
            ('ip', self.gf('maasserver.fields.MAASIPAddressField')(max_length=39, unique=True)),
            ('mac', self.gf('maasserver.fields.MACAddressField')()),
            ('nodegroup', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['maasserver.NodeGroup'])),
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
        ))
        db.send_create_signal('maasserver', ['DHCPLease'])

        # Adding model 'MACAddress'
        db.create_table('maasserver_macaddress', (
            ('node', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['maasserver.Node'], null=True, blank=True)),
            ('updated', self.gf('django.db.models.fields.DateTimeField')()),
            ('created', self.gf('django.db.models.fields.DateTimeField')()),
            ('mac_address', self.gf('maasserver.fields.MACAddressField')(unique=True)),
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('cluster_interface', self.gf('django.db.models.fields.related.ForeignKey')(default=None, to=orm['maasserver.NodeGroupInterface'], null=True, on_delete=models.SET_NULL, blank=True)),
        ))
        db.send_create_signal('maasserver', ['MACAddress'])

        # Adding M2M table for field networks on 'MACAddress'
        db.create_table('maasserver_macaddress_networks', (
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
            ('macaddress', models.ForeignKey(orm['maasserver.macaddress'], null=False)),
            ('network', models.ForeignKey(orm['maasserver.network'], null=False))
        ))
        db.create_unique('maasserver_macaddress_networks', ['macaddress_id', 'network_id'])
项目:maas    作者:maas    | 项目源码 | 文件源码
def forwards(self, orm):
        # Adding field 'Node.boot_disk'
        db.add_column('maasserver_node', 'boot_disk',
                      self.gf('django.db.models.fields.related.ForeignKey')(related_name='+', on_delete=models.SET_NULL, default=None, to=orm['maasserver.PhysicalBlockDevice'], blank=True, null=True),
                      keep_default=False)