If you want the ability to make copies of multiple records at once, or just 
want the "copy" option to appear at the top of the object list instead of 
having to click through into each record, it's pretty easy to set up an 
Admin Action. Here's one I use in a system that lets staffers duplicate 
Course records from one semester to another.  In admin.py:

# Custom Admin Action enables making a complete copy of a course (like a 
Save As...)
def make_copy(modeladmin, request, queryset):
    for obj in queryset:
        # Make a copy in memory
        # Override the ID so the db can auto_increment -- otherwise we 
overwrite the original!
        # Update the title of the new object
        n = obj
        n.id = None
        n.title = "NEW COPY OF: " + obj.title 
        n.save()
        request.user.message_set.create(message="Selected courses have been 
copied. Remember to set their Instructors and Programs!")
make_copy.short_description = "Make copies of selected courses"

.....

                
class CourseAdmin(admin.ModelAdmin):
    list_display = ('jstring','title', 'ccn', 'semester')
    search_fields = ('title','jstring__name')
    actions = [make_copy]
    form = CourseAdminForm

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/S-U4L-TOnn0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to