Ticket #10992: 10992_fix.diff
File 10992_fix.diff, 1.5 KB (added by , 16 years ago) |
---|
-
django/forms/models.py
604 603 if not self.get_queryset(): 605 604 return [] 606 605 607 # Put the objects from self.get_queryset into a dict so they are easy to lookup by pk608 existing_objects = {}609 for obj in self.get_queryset():610 existing_objects[obj.pk] = obj611 606 saved_instances = [] 612 607 for form in self.initial_forms: 613 608 pk_name = self._pk_field.name 614 609 raw_pk_value = form._raw_value(pk_name) 615 pk_value = form.fields[pk_name].clean(raw_pk_value).pk 616 obj = existing_objects[pk_value] 610 clean_data = form.fields[pk_name].clean(raw_pk_value) 611 612 if isinstance(form.fields[pk_name], ModelChoiceField): 613 # the PK field is the default implicit PK field (ModelChoiceField), and 614 # ModelChoiceField.clean() returns an object, not a raw primary key value 615 clean_pk = clean_data.pk 616 else: 617 # the PK field is of another type, like CharField or FloatField 618 clean_pk = clean_data 619 620 obj = self.get_queryset().get(pk=clean_pk) 621 617 622 if self.can_delete: 618 623 raw_delete_value = form._raw_value(DELETION_FIELD_NAME) 619 624 should_delete = form.fields[DELETION_FIELD_NAME].clean(raw_delete_value)