Commits

Matthew Schinckel committed 887df70

Added more patching functions.

  • Participants
  • Parent commits 21d19b3
  • Tags 0.1.2

Comments (0)

Files changed (3)

     
 You may pass multiple inlines.
 
-You may also pass in any combination of models or admin inlines: if a model is received, it will create a `StackedInline` for that model.
+You may also pass in any combination of models or admin inlines: if a model is received, it will create a `StackedInline` for that model.
+
+### add_actions(model, *actions)
+
+Like for inlines, but add an action.
+
+### @patch_admin(model)
+
+A decorator, that can decorate a function to be patched.
+
+    from admin_additions.patchers import patch_admin
+    
+    @patch_admin(model)
+    def patcher_function(model_admin):
+        model_admin.form = MyClassyForm
+
+This syntax is terser than the ``patch_model_admin`` function above.

admin_additions/__init__.py

-__version__ = "0.1.1"
+__version__ = "0.1.2"

admin_additions/patchers.py

     for i, inline in enumerate(inlines):
         if not issubclass(inline, admin.options.InlineModelAdmin):
             inlines[i] = type("%sInline" % inline.__name__, (admin.StackedInline,), {"model": inline})
+    
     def inner(admin):
         admin.inlines = tuple(admin.inlines) + tuple(inlines)
     
-    patch_model_admin(model, inner)
+    patch_model_admin(model, inner)
+
+def add_actions(model, *actions):
+    def inner(admin):
+        for action in actions:
+            admin.actions.append(action)
+    
+    patch_model_admin(model, inner)
+
+def patch_admin(model):
+    def inner(function):
+        patch_model_admin(model, function)
+    return inner