# 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment