Ticket #7938: 7938_force_pk_presentation.diff
File 7938_force_pk_presentation.diff, 2.6 KB (added by , 16 years ago) |
---|
-
forms/models.py
90 90 opts = model._meta 91 91 field_list = [] 92 92 for f in opts.fields + opts.many_to_many: 93 if not f.editable :93 if not f.editable and not f.primary_key: 94 94 continue 95 95 if fields and not f.name in fields: 96 96 continue … … 120 120 opts = model._meta 121 121 field_list = [] 122 122 for f in opts.fields + opts.many_to_many: 123 if not f.editable :123 if not f.editable and not f.primary_key: 124 124 continue 125 125 if fields and not f.name in fields: 126 126 continue … … 138 138 Returns a Form class for the given list of Django database field instances. 139 139 """ 140 140 fields = SortedDict([(f.name, f.formfield()) 141 for f in field_list if f.editable ])141 for f in field_list if f.editable or f.primary_key]) 142 142 return type('FormForFields', (BaseForm,), {'base_fields': fields}) 143 143 144 144 … … 161 161 opts = instance._meta 162 162 data = {} 163 163 for f in opts.fields + opts.many_to_many: 164 if not f.editable :164 if not f.editable and not f.primary_key: 165 165 continue 166 166 if fields and not f.name in fields: 167 167 continue … … 195 195 field_list = [] 196 196 opts = model._meta 197 197 for f in opts.fields + opts.many_to_many: 198 if not f.editable :198 if not f.editable and not f.primary_key: 199 199 continue 200 200 if fields and not f.name in fields: 201 201 continue … … 378 378 379 379 def add_fields(self, form, index): 380 380 """Add a hidden field for the object's primary key.""" 381 self._pk_field_name = self.model._meta.pk.attname 382 form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput) 381 if self.model._meta.has_auto_field: 382 self._pk_field_name = self.model._meta.pk.attname 383 form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput) 384 elif self.model._meta.pk.attname and not self.model._meta.pk.editable: 385 # must have the PK in the inline edits, otherwise, it cannot 386 # save them .. a generic Field as it can be any unique type 387 self._pk_field_name = self.model._meta.pk.attname 388 form.fields[self._pk_field_name] = Field(required=False, widget=HiddenInput) 383 389 super(BaseModelFormSet, self).add_fields(form, index) 384 390 385 391 def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),