I want to create a Django Admin Action that allows me to create a duplicate of a record.
Heres the use case.
Admin clicks the checkbox next to a record in an
You have the right idea but you need to iterate through the queryset then duplicate each object.
def duplicate_event(modeladmin, request, queryset):
for object in queryset:
object.id = None
object.save()
duplicate_event.short_description = "Duplicate selected record"
Maybe this work to for you.
def duplicate_query_sets(queryset, **kwargs):
for p in queryset:
p.pk = None
for i, v in kwargs.iteritems():
setattr(p, i, v)
p.save()