Create a Django Admin Action to Duplicate a Record

后端 未结 2 377
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-02 21:13

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

2条回答
  •  一生所求
    2021-01-02 21:28

    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"
    

提交回复
热议问题