Skip to content

Instantly share code, notes, and snippets.

@loic
Created November 12, 2013 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loic/7427160 to your computer and use it in GitHub Desktop.
Save loic/7427160 to your computer and use it in GitHub Desktop.
diff --git a/django/db/models/base.py b/django/db/models/base.py
index ce3f095..1d3bb12 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -360,12 +360,12 @@ class Model(six.with_metaclass(ModelBase)):
# The reason for the kwargs check is that standard iterator passes in by
# args, and instantiation for iteration is 33% faster.
args_len = len(args)
- if args_len > len(self._meta.concrete_fields):
+ if args_len > len(self._meta.fields):
# Daft, but matches old exception sans the err msg.
raise IndexError("Number of args exceeds number of fields")
if not kwargs:
- fields_iter = iter(self._meta.concrete_fields)
+ fields_iter = iter(self._meta.fields)
# The ordering of the zip calls matter - zip throws StopIteration
# when an iter throws it. So if the first iter throws it, the second
# is *not* consumed. We rely on this, so don't change the order
@@ -564,7 +564,7 @@ class Model(six.with_metaclass(ModelBase)):
# automatically do a "update_fields" save on the loaded fields.
elif not force_insert and self._deferred and using == self._state.db:
field_names = set()
- for field in self._meta.concrete_fields:
+ for field in self._meta.fields:
if not field.primary_key and not hasattr(field, 'through'):
field_names.add(field.attname)
deferred_fields = [
@@ -650,7 +650,7 @@ class Model(six.with_metaclass(ModelBase)):
for a single table.
"""
meta = cls._meta
- non_pks = [f for f in meta.local_concrete_fields if not f.primary_key]
+ non_pks = [f for f in meta.local_fields if not f.primary_key]
if update_fields:
non_pks = [f for f in non_pks
@@ -682,7 +682,7 @@ class Model(six.with_metaclass(ModelBase)):
**{field.name: getattr(self, field.attname)}).count()
self._order = order_value
- fields = meta.local_concrete_fields
+ fields = meta.local_fields
if not pk_set:
fields = [f for f in fields if not isinstance(f, AutoField)]
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index dec2e2d..50ba8e0 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -424,10 +424,7 @@ class Field(object):
def contribute_to_class(self, cls, name, virtual_only=False):
self.set_attributes_from_name(name)
self.model = cls
- if virtual_only:
- cls._meta.add_virtual_field(self)
- else:
- cls._meta.add_field(self)
+ cls._meta.add_field(self)
if self.choices:
setattr(cls, 'get_%s_display' % self.name,
curry(cls._get_FIELD_display, field=self))
diff --git a/django/forms/models.py b/django/forms/models.py
index 6d9a567..e091a0f 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -119,7 +119,7 @@ def model_to_dict(instance, fields=None, exclude=None):
from django.db.models.fields.related import ManyToManyField
opts = instance._meta
data = {}
- for f in opts.concrete_fields + opts.many_to_many:
+ for f in opts.fields + opts.many_to_many:
if not f.editable:
continue
if fields and not f.name in fields:
@@ -174,7 +174,7 @@ def fields_for_model(model, fields=None, exclude=None, widgets=None,
field_list = []
ignored = []
opts = model._meta
- for f in sorted(opts.concrete_fields + opts.many_to_many):
+ for f in sorted(opts.fields + opts.many_to_many):
if not f.editable:
continue
if fields is not None and not f.name in fields:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment