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


Python models.AutoField方法代碼示例

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


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

示例1: change_models

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def change_models(self, queryset, cleaned_data):
        n = queryset.count()

        data = {}
        fields = self.opts.fields + self.opts.many_to_many
        for f in fields:
            if not f.editable or isinstance(f, models.AutoField) \
                    or not f.name in cleaned_data:
                continue
            data[f] = cleaned_data[f.name]

        if n:
            for obj in queryset:
                for f, v in data.items():
                    f.save_form_data(obj, v)
                obj.save()
            self.message_user(_("Successfully change %(count)d %(items)s.") % {
                "count": n, "items": model_ngettext(self.opts, n)
            }, 'success') 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:21,代碼來源:batch.py

示例2: sequence_list

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def sequence_list(self):
        "Returns a list of information about all DB sequences for all models in all apps."
        from django.apps import apps
        from django.db import models, router

        sequence_list = []

        for app_config in apps.get_app_configs():
            for model in router.get_migratable_models(app_config, self.connection.alias):
                if not model._meta.managed:
                    continue
                if model._meta.swapped:
                    continue
                for f in model._meta.local_fields:
                    if isinstance(f, models.AutoField):
                        sequence_list.append({'table': model._meta.db_table, 'column': f.column})
                        break  # Only one AutoField is allowed per model, so don't bother continuing.

                for f in model._meta.local_many_to_many:
                    # If this is an m2m using an intermediate table,
                    # we don't need to reset the sequence.
                    if f.rel.through is None:
                        sequence_list.append({'table': f.m2m_db_table(), 'column': None})

        return sequence_list 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:27,代碼來源:introspection.py

示例3: sequence_reset_sql

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def sequence_reset_sql(self, style, model_list):
        from django.db import models
        output = []
        query = self._sequence_reset_sql
        for model in model_list:
            for f in model._meta.local_fields:
                if isinstance(f, models.AutoField):
                    table_name = self.quote_name(model._meta.db_table)
                    sequence_name = self._get_sequence_name(model._meta.db_table)
                    column_name = self.quote_name(f.column)
                    output.append(query % {'sequence': sequence_name,
                                           'table': table_name,
                                           'column': column_name})
                    # Only one AutoField is allowed per model, so don't
                    # continue to loop
                    break
            for f in model._meta.many_to_many:
                if not f.rel.through:
                    table_name = self.quote_name(f.m2m_db_table())
                    sequence_name = self._get_sequence_name(f.m2m_db_table())
                    column_name = self.quote_name('id')
                    output.append(query % {'sequence': sequence_name,
                                           'table': table_name,
                                           'column': column_name})
        return output 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:27,代碼來源:operations.py

示例4: forwards

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def forwards(self, orm):
        # Adding model 'Project'
        db.create_table('api_project', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('name', self.gf('django.db.models.fields.CharField')(max_length=255)),
            ('organization', self.gf('django.db.models.fields.related.ForeignKey')(related_name='project_organization', to=orm['auth.User'])),
            ('created_by', self.gf('django.db.models.fields.related.ForeignKey')(related_name='project_creator', to=orm['auth.User'])),
            ('date_created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
            ('date_modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
        ))
        db.send_create_signal('api', ['Project'])

        # Adding unique constraint on 'Project', fields ['name', 'organization']
        db.create_unique('api_project', ['name', 'organization_id'])

        # Adding M2M table for field projects on 'Team'
        db.create_table('api_team_projects', (
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
            ('team', models.ForeignKey(orm['api.team'], null=False)),
            ('project', models.ForeignKey(orm['api.project'], null=False))
        ))
        db.create_unique('api_team_projects', ['team_id', 'project_id']) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:24,代碼來源:0002_auto__add_project__add_unique_project_name_organization.py

示例5: get_field_type

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def get_field_type(self, data_type, description):
        if data_type == cx_Oracle.NUMBER:
            precision, scale = description[4:6]
            if scale == 0:
                if precision > 11:
                    return 'BigAutoField' if description.is_autofield else 'BigIntegerField'
                elif precision == 1:
                    return 'BooleanField'
                elif description.is_autofield:
                    return 'AutoField'
                else:
                    return 'IntegerField'
            elif scale == -127:
                return 'FloatField'

        return super().get_field_type(data_type, description) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:18,代碼來源:introspection.py

示例6: get_migrations_for_django_21_and_newer

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def get_migrations_for_django_21_and_newer():
    return [
        # remove primary key information from 'key' field
        migrations.AlterField(
            model_name='resetpasswordtoken',
            name='key',
            field=models.CharField(db_index=True, primary_key=False, max_length=64, unique=True, verbose_name='Key'),
        ),
        # add a new id field
        migrations.AddField(
            model_name='resetpasswordtoken',
            name='id',
            field=models.AutoField(primary_key=True, serialize=False),
            preserve_default=False,
        ),
        migrations.RunPython(
            populate_auto_incrementing_pk_field,
            migrations.RunPython.noop
        ),
    ] 
開發者ID:anexia-it,項目名稱:django-rest-passwordreset,代碼行數:22,代碼來源:0002_pk_migration.py

示例7: sequence_list

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def sequence_list(self):
        "Returns a list of information about all DB sequences for all models in all apps."
        from django.apps import apps
        from django.db import models, router

        sequence_list = []

        for app_config in apps.get_app_configs():
            for model in router.get_migratable_models(app_config, self.connection.alias):
                if not model._meta.managed:
                    continue
                if model._meta.swapped:
                    continue
                for f in model._meta.local_fields:
                    if isinstance(f, models.AutoField):
                        sequence_list.append({'table': model._meta.db_table, 'column': f.column})
                        break  # Only one AutoField is allowed per model, so don't bother continuing.

                for f in model._meta.local_many_to_many:
                    # If this is an m2m using an intermediate table,
                    # we don't need to reset the sequence.
                    if f.remote_field.through is None:
                        sequence_list.append({'table': f.m2m_db_table(), 'column': None})

        return sequence_list 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:27,代碼來源:introspection.py

示例8: sequence_reset_sql

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def sequence_reset_sql(self, style, model_list):
        from django.db import models
        output = []
        query = self._sequence_reset_sql
        for model in model_list:
            for f in model._meta.local_fields:
                if isinstance(f, models.AutoField):
                    table_name = self.quote_name(model._meta.db_table)
                    sequence_name = self._get_sequence_name(model._meta.db_table)
                    column_name = self.quote_name(f.column)
                    output.append(query % {'sequence': sequence_name,
                                           'table': table_name,
                                           'column': column_name})
                    # Only one AutoField is allowed per model, so don't
                    # continue to loop
                    break
            for f in model._meta.many_to_many:
                if not f.remote_field.through:
                    table_name = self.quote_name(f.m2m_db_table())
                    sequence_name = self._get_sequence_name(f.m2m_db_table())
                    column_name = self.quote_name('id')
                    output.append(query % {'sequence': sequence_name,
                                           'table': table_name,
                                           'column': column_name})
        return output 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:27,代碼來源:operations.py

示例9: forwards

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def forwards(self, orm):
        # Adding model 'Flowbit'
        db.create_table(u'rules_flowbit', (
            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
            ('set', self.gf('django.db.models.fields.BooleanField')(default=False)),
            ('isset', self.gf('django.db.models.fields.BooleanField')(default=False)),
            ('enable', self.gf('django.db.models.fields.BooleanField')(default=True)),
            ('source', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['rules.Source'])),
        ))
        db.send_create_signal(u'rules', ['Flowbit'])

        # Adding M2M table for field flowbits on 'Rule'
        m2m_table_name = db.shorten_name(u'rules_rule_flowbits')
        db.create_table(m2m_table_name, (
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
            ('rule', models.ForeignKey(orm[u'rules.rule'], null=False)),
            ('flowbit', models.ForeignKey(orm[u'rules.flowbit'], null=False))
        ))
        db.create_unique(m2m_table_name, ['rule_id', 'flowbit_id']) 
開發者ID:StamusNetworks,項目名稱:scirius,代碼行數:22,代碼來源:0006_auto__add_flowbit.py

示例10: change_models

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def change_models(self, queryset, cleaned_data):
        n = queryset.count()

        data = {}
        for f in self.opts.fields:
            if not f.editable or isinstance(f, models.AutoField) \
                    or not f.name in cleaned_data:
                continue
            data[f] = cleaned_data[f.name]

        if n:
            for obj in queryset:
                for f, v in data.items():
                    f.save_form_data(obj, v)
                obj.save()
            self.message_user(_("Successfully change %(count)d %(items)s.") % {
                "count": n, "items": model_ngettext(self.opts, n)
            }, 'success') 
開發者ID:madre,項目名稱:devops,代碼行數:20,代碼來源:batch.py

示例11: _test_create_model

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def _test_create_model(self, app_label, should_run):
        """
        CreateModel honors multi-db settings.
        """
        operation = migrations.CreateModel(
            "Pony",
            [("id", models.AutoField(primary_key=True))],
        )
        # Test the state alteration
        project_state = ProjectState()
        new_state = project_state.clone()
        operation.state_forwards(app_label, new_state)
        # Test the database alteration
        self.assertTableNotExists("%s_pony" % app_label)
        with connection.schema_editor() as editor:
            operation.database_forwards(app_label, editor, project_state, new_state)
        if should_run:
            self.assertTableExists("%s_pony" % app_label)
        else:
            self.assertTableNotExists("%s_pony" % app_label)
        # And test reversal
        with connection.schema_editor() as editor:
            operation.database_backwards(app_label, editor, new_state, project_state)
        self.assertTableNotExists("%s_pony" % app_label) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:26,代碼來源:test_multidb.py

示例12: forwards

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def forwards(self, orm):
        # Adding model 'Organization'
        db.create_table(u'crowdataapp_organization', (
            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('name', self.gf('django.db.models.fields.CharField')(max_length='128')),
            ('description', self.gf('django.db.models.fields.TextField')()),
        ))
        db.send_create_signal(u'crowdataapp', ['Organization'])

        # Adding M2M table for field users on 'Organization'
        m2m_table_name = db.shorten_name(u'crowdataapp_organization_users')
        db.create_table(m2m_table_name, (
            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
            ('organization', models.ForeignKey(orm[u'crowdataapp.organization'], null=False)),
            ('user', models.ForeignKey(orm[u'auth.user'], null=False))
        ))
        db.create_unique(m2m_table_name, ['organization_id', 'user_id'])

        # Adding field 'DocumentSetFormEntry.organization'
        db.add_column(u'crowdataapp_documentsetformentry', 'organization',
                      self.gf('django.db.models.fields.related.ForeignKey')(to=orm['crowdataapp.Organization'], null=True, blank=True),
                      keep_default=False)

        # Adding field 'UserProfile.current_organization'
        db.add_column(u'crowdataapp_userprofile', 'current_organization',
                      self.gf('django.db.models.fields.related.ForeignKey')(to=orm['crowdataapp.Organization'], null=True, blank=True),
                      keep_default=False) 
開發者ID:crowdata,項目名稱:crowdata,代碼行數:29,代碼來源:0028_auto__add_organization__add_field_documentsetformentry_organization__a.py

示例13: _done

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def _done(self):
        cleaned_data = self.get_all_cleaned_data()
        exclude = self.admin_view.exclude

        opts = self.admin_view.opts
        instance = self.admin_view.org_obj or self.admin_view.model()

        file_field_list = []
        for f in opts.fields:
            if not f.editable or isinstance(f, models.AutoField) \
                    or not f.name in cleaned_data:
                continue
            if exclude and f.name in exclude:
                continue
            # Defer saving file-type fields until after the other fields, so a
            # callable upload_to can use the values from other fields.
            if isinstance(f, models.FileField):
                file_field_list.append(f)
            else:
                f.save_form_data(instance, cleaned_data[f.name])

        for f in file_field_list:
            f.save_form_data(instance, cleaned_data[f.name])

        instance.save()

        for f in opts.many_to_many:
            if f.name in cleaned_data:
                f.save_form_data(instance, cleaned_data[f.name])

        self.admin_view.new_obj = instance 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:33,代碼來源:wizard.py

示例14: construct_instance

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def construct_instance(form, instance, fields=None, exclude=None):
    """
    Constructs and returns a model instance from the bound ``form``'s
    ``cleaned_data``, but does not save the returned instance to the
    database.
    """
    from django.db import models
    opts = instance._meta

    cleaned_data = form.cleaned_data
    file_field_list = []
    for f in opts.fields:
        if not f.editable or isinstance(f, models.AutoField) \
                or f.name not in cleaned_data:
            continue
        if fields is not None and f.name not in fields:
            continue
        if exclude and f.name in exclude:
            continue
        # Defer saving file-type fields until after the other fields, so a
        # callable upload_to can use the values from other fields.
        if isinstance(f, models.FileField):
            file_field_list.append(f)
        else:
            f.save_form_data(instance, cleaned_data[f.name])

    for f in file_field_list:
        f.save_form_data(instance, cleaned_data[f.name])

    return instance 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:32,代碼來源:models.py

示例15: add_fields

# 需要導入模塊: from django.db import models [as 別名]
# 或者: from django.db.models import AutoField [as 別名]
def add_fields(self, form, index):
        """Add a hidden field for the object's primary key."""
        from django.db.models import AutoField, OneToOneField, ForeignKey
        self._pk_field = pk = self.model._meta.pk
        # If a pk isn't editable, then it won't be on the form, so we need to
        # add it here so we can tell which object is which when we get the
        # data back. Generally, pk.editable should be false, but for some
        # reason, auto_created pk fields and AutoField's editable attribute is
        # True, so check for that as well.

        def pk_is_not_editable(pk):
            return ((not pk.editable) or (pk.auto_created or isinstance(pk, AutoField))
                or (pk.rel and pk.rel.parent_link and pk_is_not_editable(pk.rel.to._meta.pk)))
        if pk_is_not_editable(pk) or pk.name not in form.fields:
            if form.is_bound:
                # If we're adding the related instance, ignore its primary key
                # as it could be an auto-generated default which isn't actually
                # in the database.
                pk_value = None if form.instance._state.adding else form.instance.pk
            else:
                try:
                    if index is not None:
                        pk_value = self.get_queryset()[index].pk
                    else:
                        pk_value = None
                except IndexError:
                    pk_value = None
            if isinstance(pk, OneToOneField) or isinstance(pk, ForeignKey):
                qs = pk.rel.to._default_manager.get_queryset()
            else:
                qs = self.model._default_manager.get_queryset()
            qs = qs.using(form.instance._state.db)
            if form._meta.widgets:
                widget = form._meta.widgets.get(self._pk_field.name, HiddenInput)
            else:
                widget = HiddenInput
            form.fields[self._pk_field.name] = ModelChoiceField(qs, initial=pk_value, required=False, widget=widget)
        super(BaseModelFormSet, self).add_fields(form, index) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:40,代碼來源:models.py


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