Ticket #7865: admin_site_add_to_inlines.diff

File admin_site_add_to_inlines.diff, 1.1 KB (added by magneto, 16 years ago)

A 'add_to_inlines' funciton for AdminSite

  • django/contrib/admin/sites.py

     
    9494                raise NotRegistered('The model %s is not registered' % model.__name__)
    9595            del self._registry[model]
    9696
     97    def add_to_inlines(self, target_model, inline_admin_classes):
     98        if target_model not in self._registry:
     99            return False
     100        if not hasattr(inline_admin_classes, '__iter__'):
     101            inline_admin_classes = [inline_admin_classes]
     102        for cls in inline_admin_classes:
     103            inline_instance = cls(self._registry[target_model].model, self._registry[target_model].admin_site)
     104            if inline_instance not in self._registry[target_model].inline_instances:
     105                self._registry[target_model].inline_instances.append(inline_instance)
     106        return True
     107
    97108    def has_permission(self, request):
    98109        """
    99110        Returns True if the given HttpRequest has permission to view
Back to Top