Ticket #1939: inline_multiple_foreign.diff

File inline_multiple_foreign.diff, 4.4 KB (added by Joel Heenan <joelh-django@…>, 18 years ago)

patch for ticket 1939

  • django/db/models/options.py

     
    134134    def get_data_holders(self, follow=None):
    135135        if follow == None:
    136136            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)]
    138142
    139143    def get_follow(self, override=None):
    140144        follow = {}
  • django/db/models/manipulators.py

     
    22from django import forms
    33from django.core import validators
    44from django.db.models.fields import FileField, AutoField
     5from django.db.models.fields.related import ForeignKey
    56from django.dispatch import dispatcher
    67from django.db.models import signals
    78from django.utils.functional import curry
     
    130131
    131132        expanded_data = DotExpandedDict(dict(new_data))
    132133        # Save many-to-one objects. Example: Add the Choice objects for a Poll.
     134        alreadyFollowed = []
    133135        for related in self.opts.get_all_related_objects():
    134136            # Create obj_list, which is a DotExpandedDict such as this:
    135137            # [('0', {'id': ['940'], 'choice': ['This is the first choice']}),
     
    137139            #  ('2', {'id': [''], 'choice': ['']})]
    138140            child_follow = self.follow.get(related.name, None)
    139141
     142            if(child_follow in alreadyFollowed):
     143                continue
     144            alreadyFollowed.append(child_follow)
     145
    140146            if child_follow:
    141147                obj_list = expanded_data.get(related.var_name, {}).items()
    142148                if not obj_list:
     
    167173                                pass
    168174
    169175                    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, ''):
    171177                            all_cores_given = False
    172178                        elif f.core and not isinstance(f, FileField) and f.get_manipulator_new_data(rel_new_data, rel=True) not in (None, ''):
    173179                            all_cores_blank = False
     
    177183                        # case, because they'll be dealt with later.
    178184
    179185                        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)
    181190                        elif (not self.change) and isinstance(f, AutoField):
    182191                            param = None
    183192                        elif self.change and (isinstance(f, FileField) or not child_follow.get(f.name, None)):
  • django/contrib/admin/views/main.py

     
    195195    bound_field_sets = [field_set.bind(context['form'], original, AdminBoundFieldSet) for field_set in field_sets]
    196196    first_form_field_id = bound_field_sets[0].bound_field_lines[0].bound_fields[0].form_fields[0].get_id();
    197197    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       
    199204    extra_context = {
    200205        'add': add,
    201206        'change': change,
Back to Top