Ticket #4491: newforms-admin-5427-site_to_admin_opts.diff

File newforms-admin-5427-site_to_admin_opts.diff, 3.2 KB (added by Honza Král <Honza.Kral@…>, 17 years ago)

propagate site to admin_class

  • django/contrib/admin/options.py

     
    114114    filter_vertical = ()
    115115    filter_horizontal = ()
    116116
    117     def __init__(self, model):
     117    def __init__(self, model, site):
    118118        self.model = model
    119119        self.opts = model._meta
     120        self.site = site
    120121
    121122    def __call__(self, request, url):
    122123        # Check that LogEntry, ContentType and the auth context processor are installed.
     
    238239                # Wrap the widget's render() method with a method that adds
    239240                # extra HTML to the end of the rendered output.
    240241                formfield = db_field.formfield(**kwargs)
    241                 formfield.widget.render = widgets.RelatedFieldWidgetWrapper(formfield.widget.render, db_field.rel)
     242                formfield.widget.render = widgets.RelatedFieldWidgetWrapper(formfield.widget.render, db_field.rel, self.site)
    242243                return formfield
    243244
    244245        # For any other type of field, just call its formfield() method.
  • django/contrib/admin/widgets.py

     
    7474    This class is a wrapper whose __call__() method mimics the interface of a
    7575    Widget's render() method.
    7676    """
    77     def __init__(self, render_func, rel):
    78         self.render_func, self.rel = render_func, rel
     77    def __init__(self, render_func, rel, site):
     78        self.render_func, self.rel, self.site = render_func, rel, site
    7979
    8080    def __call__(self, name, value, *args, **kwargs):
    8181        from django.conf import settings
    8282        rel_to = self.rel.to
    8383        related_url = '../../../%s/%s/' % (rel_to._meta.app_label, rel_to._meta.object_name.lower())
    8484        output = [self.render_func(name, value, *args, **kwargs)]
    85         if rel_to._meta.admin: # If the related object has an admin interface:
     85        if rel_to in self.site._registry: # If the related object has an admin interface:
    8686            # TODO: "id_" is hard-coded here. This should instead use the correct
    8787            # API to determine the ID dynamically.
     88            output
    8889            output.append(u'<a href="%sadd/" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \
    8990                (related_url, name))
    9091            output.append(u'<img src="%simg/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a>' % settings.ADMIN_MEDIA_PREFIX)
  • django/contrib/admin/sites.py

     
    7475        for model in model_or_iterable:
    7576            if model in self._registry:
    7677                raise AlreadyRegistered('The model %s is already registered' % model.__class__.__name__)
    77             self._registry[model] = admin_class(model)
     78            self._registry[model] = admin_class(model, self)
    7879
    7980    def unregister(self, model_or_iterable):
    8081        """
Back to Top