mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
newforms-admin: Small cleanup of a bunch of _get_pk_val() calls.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6840 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
081d0ed889
commit
f0a54c0240
@ -144,7 +144,7 @@ class QuerySetIterator(object):
|
|||||||
if self.empty_label is not None:
|
if self.empty_label is not None:
|
||||||
yield (u"", self.empty_label)
|
yield (u"", self.empty_label)
|
||||||
for obj in self.queryset:
|
for obj in self.queryset:
|
||||||
yield (obj._get_pk_val(), smart_unicode(obj))
|
yield (obj.pk, smart_unicode(obj))
|
||||||
# Clear the QuerySet cache if required.
|
# Clear the QuerySet cache if required.
|
||||||
if not self.cache_choices:
|
if not self.cache_choices:
|
||||||
self.queryset._result_cache = None
|
self.queryset._result_cache = None
|
||||||
@ -266,7 +266,7 @@ def initial_data(instance, fields=None):
|
|||||||
continue
|
continue
|
||||||
if isinstance(f, ManyToManyField):
|
if isinstance(f, ManyToManyField):
|
||||||
# MultipleChoiceWidget needs a list of ints, not object instances.
|
# MultipleChoiceWidget needs a list of ints, not object instances.
|
||||||
initial[f.name] = [obj._get_pk_val() for obj in f.value_from_object(instance)]
|
initial[f.name] = [obj.pk for obj in f.value_from_object(instance)]
|
||||||
else:
|
else:
|
||||||
initial[f.name] = f.value_from_object(instance)
|
initial[f.name] = f.value_from_object(instance)
|
||||||
return initial
|
return initial
|
||||||
@ -304,7 +304,7 @@ class BaseModelFormSet(BaseFormSet):
|
|||||||
# Put the objects from self.get_queryset into a dict so they are easy to lookup by pk
|
# Put the objects from self.get_queryset into a dict so they are easy to lookup by pk
|
||||||
existing_objects = {}
|
existing_objects = {}
|
||||||
for obj in self.queryset:
|
for obj in self.queryset:
|
||||||
existing_objects[obj._get_pk_val()] = obj
|
existing_objects[obj.pk] = obj
|
||||||
saved_instances = []
|
saved_instances = []
|
||||||
for form in self.change_forms:
|
for form in self.change_forms:
|
||||||
obj = existing_objects[form.cleaned_data[self.model._meta.pk.attname]]
|
obj = existing_objects[form.cleaned_data[self.model._meta.pk.attname]]
|
||||||
@ -367,7 +367,7 @@ class InlineFormset(BaseModelFormSet):
|
|||||||
return self.model._default_manager.filter(**kwargs)
|
return self.model._default_manager.filter(**kwargs)
|
||||||
|
|
||||||
def save_new(self, form, commit=True):
|
def save_new(self, form, commit=True):
|
||||||
kwargs = {self.fk.get_attname(): self.instance.pk}
|
kwargs = {self.fk.get_attname(): self.instance._get_pk_val()}
|
||||||
new_obj = self.model(**kwargs)
|
new_obj = self.model(**kwargs)
|
||||||
return save_instance(form, new_obj, commit=commit)
|
return save_instance(form, new_obj, commit=commit)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user