Code

Ticket #1113: 1113.patch

File 1113.patch, 1.5 KB (added by jacob, 7 years ago)

Hopefully a final fix :)

  • main.py

     
    9797        self.mod, self.opts = _get_mod_opts(app_label, module_name) 
    9898        if not request.user.has_perm(app_label + '.' + self.opts.get_change_permission()): 
    9999            raise PermissionDenied 
     100         
     101        lookup_mod, lookup_opts = self.mod, self.opts 
     102        if self.opts.one_to_one_field: 
     103            lookup_mod = self.opts.one_to_one_field.rel.to.get_model_module() 
     104            lookup_opts = lookup_mod.Klass._meta 
     105            # If lookup_opts doesn't have admin set, give it the default meta.Admin(). 
     106            if not lookup_opts.admin:  
     107                lookup_opts.admin = meta.Admin() 
     108         
     109        self.lookup_mod, self.lookup_opts = lookup_mod, lookup_opts 
    100110 
    101         self.lookup_mod, self.lookup_opts = self.mod, self.opts 
    102  
    103111    def get_search_parameters(self, request): 
    104112        # Get search parameters from the query string. 
    105113        try: 
     
    226234                    or_queries.append(meta.Q(**{'%s__icontains' % field_name: bit})) 
    227235                complex_queries.append(reduce(operator.or_, or_queries)) 
    228236            lookup_params['complex'] = reduce(operator.and_, complex_queries) 
     237        if opts.one_to_one_field: 
     238            lookup_params.update(opts.one_to_one_field.rel.limit_choices_to)  
    229239        self.lookup_params = lookup_params 
    230240 
    231241def change_list(request, app_label, module_name):