Ticket #12025: t12025_r11366.patch

File t12025_r11366.patch, 2.0 KB (added by rui.coelho@…, 15 years ago)
  • django/db/models/options.py

     
    412412                    cache[obj] = parent
    413413                else:
    414414                    cache[obj] = model
     415        from django.contrib.contenttypes import generic           
    415416        for klass in get_models():
    416417            for f in klass._meta.local_many_to_many:
    417                 if f.rel and not isinstance(f.rel.to, str) and self == f.rel.to._meta:
     418                if f.rel and isinstance(f, generic.GenericRelation) and self == klass._meta:
     419                    cache[RelatedObject(klass, f.rel.to, f)] = None           
     420                elif f.rel and not isinstance(f.rel.to, str) and self == f.rel.to._meta:
    418421                    cache[RelatedObject(f.rel.to, klass, f)] = None
    419422        if app_cache_ready():
    420423            self._related_many_to_many_cache = cache
  • django/contrib/admin/util.py

     
    146146                p = '%s.%s' % (related.opts.app_label, related.opts.get_delete_permission())
    147147                if not user.has_perm(p):
    148148                    perms_needed.add(related.opts.verbose_name)
     149    from django.contrib.contenttypes import generic
    149150    for related in opts.get_all_related_many_to_many_objects():
    150151        has_admin = related.model in admin_site._registry
    151152        if related.opts in opts_seen:
     
    156157
    157158        # related.get_accessor_name() could return None for symmetrical relationships
    158159        if rel_opts_name:
    159             rel_objs = getattr(obj, rel_opts_name, None)
     160            rel_objs = getattr(obj, rel_opts_name, None) or \
     161                (isinstance(related.field, generic.GenericRelation) and getattr(obj, related.field.verbose_name, None))               
    160162            if rel_objs:
    161163                has_related_objs = True
    162164
Back to Top