Ticket #1939: inline_multiple_foreign.diff
File inline_multiple_foreign.diff, 4.4 KB (added by , 18 years ago) |
---|
-
django/db/models/options.py
134 134 def get_data_holders(self, follow=None): 135 135 if follow == None: 136 136 follow = self.get_follow() 137 return [f for f in self.fields + self.many_to_many + self.get_all_related_objects() if follow.get(f.name, None)] 137 res = [] 138 res += [f for f in self.fields + self.many_to_many if follow.get(f.name,None)] 139 res += [f for f in self.get_all_related_objects() if f.edit_inline] 140 return res 141 #return [f for f in self.fields + self.many_to_many + self.get_all_related_objects() if follow.get(f.name, None)] 138 142 139 143 def get_follow(self, override=None): 140 144 follow = {} -
django/db/models/manipulators.py
2 2 from django import forms 3 3 from django.core import validators 4 4 from django.db.models.fields import FileField, AutoField 5 from django.db.models.fields.related import ForeignKey 5 6 from django.dispatch import dispatcher 6 7 from django.db.models import signals 7 8 from django.utils.functional import curry … … 130 131 131 132 expanded_data = DotExpandedDict(dict(new_data)) 132 133 # Save many-to-one objects. Example: Add the Choice objects for a Poll. 134 alreadyFollowed = [] 133 135 for related in self.opts.get_all_related_objects(): 134 136 # Create obj_list, which is a DotExpandedDict such as this: 135 137 # [('0', {'id': ['940'], 'choice': ['This is the first choice']}), … … 137 139 # ('2', {'id': [''], 'choice': ['']})] 138 140 child_follow = self.follow.get(related.name, None) 139 141 142 if(child_follow in alreadyFollowed): 143 continue 144 alreadyFollowed.append(child_follow) 145 140 146 if child_follow: 141 147 obj_list = expanded_data.get(related.var_name, {}).items() 142 148 if not obj_list: … … 167 173 pass 168 174 169 175 for f in related.opts.fields: 170 if f.core and not isinstance(f, FileField) and f.get_manipulator_new_data(rel_new_data, rel=True) in (None, ''):176 if f.core and not isinstance(f, FileField) and not isinstance(f,ForeignKey) and f.get_manipulator_new_data(rel_new_data, rel=True) in (None, ''): 171 177 all_cores_given = False 172 178 elif f.core and not isinstance(f, FileField) and f.get_manipulator_new_data(rel_new_data, rel=True) not in (None, ''): 173 179 all_cores_blank = False … … 177 183 # case, because they'll be dealt with later. 178 184 179 185 if f == related.field: 180 param = getattr(new_object, related.field.rel.field_name) 186 if(related.field.rel.to == self.model and not f.rel.edit_inline): 187 param = f.get_manipulator_new_data(rel_new_data,rel=True) 188 else: 189 param = getattr(new_object, related.field.rel.field_name) 181 190 elif (not self.change) and isinstance(f, AutoField): 182 191 param = None 183 192 elif self.change and (isinstance(f, FileField) or not child_follow.get(f.name, None)): -
django/contrib/admin/views/main.py
195 195 bound_field_sets = [field_set.bind(context['form'], original, AdminBoundFieldSet) for field_set in field_sets] 196 196 first_form_field_id = bound_field_sets[0].bound_field_lines[0].bound_fields[0].form_fields[0].get_id(); 197 197 ordered_objects = opts.get_ordered_objects() 198 inline_related_objects = opts.get_followed_related_objects(manipulator.follow) 198 followed_objects = opts.get_followed_related_objects(manipulator.follow) 199 inline_related_objects = [] 200 for obj in followed_objects: 201 if(obj.edit_inline): 202 inline_related_objects.append(obj) 203 199 204 extra_context = { 200 205 'add': add, 201 206 'change': change,