Ticket #4491: site-aware-modeladmin.diff
File site-aware-modeladmin.diff, 5.3 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/options.py
118 118 fields = None 119 119 filter_vertical = () 120 120 filter_horizontal = () 121 prepopulated_fields = {} 122 121 123 def formfield_for_dbfield(self, db_field, **kwargs): 122 124 """ 123 125 Hook for specifying the form Field instance for a given database Field … … 155 157 # Wrap the widget's render() method with a method that adds 156 158 # extra HTML to the end of the rendered output. 157 159 formfield = db_field.formfield(**kwargs) 158 formfield.widget.render = widgets.RelatedFieldWidgetWrapper(formfield.widget.render, db_field.rel )160 formfield.widget.render = widgets.RelatedFieldWidgetWrapper(formfield.widget.render, db_field.rel, self.admin_site) 159 161 return formfield 160 162 161 163 # For any other type of field, just call its formfield() method. … … 175 177 save_as = False 176 178 save_on_top = False 177 179 ordering = None 178 prepopulated_fields = {}179 180 inlines = [] 180 181 181 def __init__(self, model ):182 def __init__(self, model, admin_site): 182 183 self.model = model 183 184 self.opts = model._meta 185 self.admin_site = admin_site 184 186 185 187 def __call__(self, request, url): 186 188 # Check that LogEntry, ContentType and the auth context processor are installed. … … 610 612 611 613 def get_inline_formsets(self): 612 614 inline_formset_classes = [] 613 for opts in self.inlines:615 for opts in [obj(self.admin_site) for obj in self.inlines]: 614 616 inline = forms.inline_formset(self.model, opts.model, formfield_callback=opts.formfield_for_dbfield, fields=opts.fields, extra=opts.extra) 615 617 inline_formset_classes.append(inline) 616 618 return inline_formset_classes … … 623 625 ``model`` to its parent. This is required if ``model`` has more than one 624 626 ``ForeignKey`` to its parent. 625 627 """ 626 def __init__(self, model, name=None, extra=3, fields=None, template=None, raw_id_fields=None): 627 self.model = model 628 self.opts = model._meta 629 self.name = name 630 self.extra = extra 631 self.fields = fields 632 self.template = template or self.default_template 633 self.verbose_name = model._meta.verbose_name 634 self.verbose_name_plural = model._meta.verbose_name_plural 635 self.prepopulated_fields = {} 636 self.raw_id_fields = raw_id_fields or () 628 model = None 629 name = None 630 extra = 3 631 template = None 632 verbose_name = None 633 verbose_name_plural = None 637 634 635 def __init__(self, admin_site): 636 self.admin_site = admin_site 637 self.opts = self.model._meta 638 if not self.verbose_name: 639 self.verbose_name = self.model._meta.verbose_name 640 if not self.verbose_name_plural: 641 self.verbose_name_plural = self.model._meta.verbose_name_plural 642 638 643 class StackedInline(InlineModelAdmin): 639 default_template = 'admin/edit_inline_stacked.html'644 template = 'admin/edit_inline_stacked.html' 640 645 641 646 class TabularInline(InlineModelAdmin): 642 default_template = 'admin/edit_inline_tabular.html'647 template = 'admin/edit_inline_tabular.html' 643 648 644 649 class BoundInline(object): 645 650 def __init__(self, inline_admin, formset): -
django/contrib/admin/widgets.py
91 91 This class is a wrapper whose __call__() method mimics the interface of a 92 92 Widget's render() method. 93 93 """ 94 def __init__(self, render_func, rel ):94 def __init__(self, render_func, rel, admin_site): 95 95 self.render_func, self.rel = render_func, rel 96 # so we can check if the related object is registered with this AdminSite 97 self.admin_site = admin_site 96 98 97 99 def __call__(self, name, value, *args, **kwargs): 98 100 from django.conf import settings 99 101 rel_to = self.rel.to 100 102 related_url = '../../../%s/%s/' % (rel_to._meta.app_label, rel_to._meta.object_name.lower()) 101 103 output = [self.render_func(name, value, *args, **kwargs)] 102 if rel_to ._meta.admin: # If the related object has an admin interface:104 if rel_to in self.admin_site._registry: # If the related object has an admin interface: 103 105 # TODO: "id_" is hard-coded here. This should instead use the correct 104 106 # API to determine the ID dynamically. 105 107 output.append(u'<a href="%sadd/" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \ -
django/contrib/admin/sites.py
77 77 for model in model_or_iterable: 78 78 if model in self._registry: 79 79 raise AlreadyRegistered('The model %s is already registered' % model.__name__) 80 self._registry[model] = admin_class(model )80 self._registry[model] = admin_class(model, self) 81 81 82 82 def unregister(self, model_or_iterable): 83 83 """