Ticket #8241: 8241.patch
File 8241.patch, 2.2 KB (added by , 16 years ago) |
---|
-
db/models/fields/related.py
726 726 """ 727 727 def __init__(self, to, to_field=None, **kwargs): 728 728 kwargs['unique'] = True 729 kwargs['editable'] = False 729 if kwargs.get('parent_link', False): 730 kwargs.setdefault('editable', False) 730 731 if 'num_in_admin' not in kwargs: 731 732 kwargs['num_in_admin'] = 0 732 733 super(OneToOneField, self).__init__(to, to_field, OneToOneRel, **kwargs) -
forms/models.py
115 115 else: 116 116 # MultipleChoiceWidget needs a list of pks, not object instances. 117 117 data[f.name] = [obj.pk for obj in f.value_from_object(instance)] 118 elif f.primary_key: 119 data[f.attname] = f.value_from_object(instance) 118 120 else: 119 121 data[f.name] = f.value_from_object(instance) 120 122 return data … … 289 291 existing_objects[obj.pk] = obj 290 292 saved_instances = [] 291 293 for form in self.initial_forms: 292 obj = existing_objects[form.cleaned_data[self. model._meta.pk.attname]]294 obj = existing_objects[form.cleaned_data[self._pk_field_name]] 293 295 if self.can_delete and form.cleaned_data[DELETION_FIELD_NAME]: 294 296 self.deleted_objects.append(obj) 295 297 obj.delete() … … 317 319 318 320 def add_fields(self, form, index): 319 321 """Add a hidden field for the object's primary key.""" 320 if self.model._meta.has_auto_field: 321 self._pk_field_name = self.model._meta.pk.attname 322 form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput) 322 self._pk_field_name = self.model._meta.pk.attname 323 form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput) 323 324 super(BaseModelFormSet, self).add_fields(form, index) 324 325 325 326 def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),