Browse Source

Add document copy to admin interface

Jocelyn Delande 9 years ago
parent
commit
6e45454c5b
2 changed files with 13 additions and 2 deletions
  1. 13 1
      costs/admin.py
  2. 0 1
      costs/models.py

+ 13 - 1
costs/admin.py

@@ -1,4 +1,6 @@
 from django.contrib import admin
+from django.core.urlresolvers import reverse
+from django.utils.safestring import mark_safe
 
 from .models import (
     Document, Cost, Good, CostUse, GoodUse, Service, ServiceUse)
@@ -7,7 +9,17 @@ from .models import (
 @admin.register(Document)
 class DocumentAdmin(admin.ModelAdmin):
     list_display = ('name', 'date', 'type')
-
+    actions = ['copy']
+
+    def copy(self, request, queryset):
+        for i in queryset.all():
+            new = i.copy()
+            edit_url = reverse('admin:costs_document_change', args=(new.pk,))
+            self.message_user(
+                request, mark_safe(
+                    "{} copié, pensez à <a href=\"{}\">L'éditer</a>".format(
+                        new, edit_url)))
+    copy.short_description = 'Copier'
 
 class GoodUseInline(admin.TabularInline):
     model = GoodUse

+ 0 - 1
costs/models.py

@@ -1,4 +1,3 @@
-import copy
 import datetime
 from itertools import chain