Milano
Milano

Reputation: 18725

"No action selected" says Django-admin when deleting objects

I've created a simple model Product with couple of fields and then went to admin.py. I've registered the Product, make some fields list_editable and created a new action duplicate.

def duplicate(modeladmin, request, queryset):
    number = int(request.POST['number'])
    product = queryset.first()
    for i in xrange(number):
        product.id = None
        product.save()

class DuplicateActionForm(ActionForm):
    number = forms.IntegerField()

class ProductAdmin(admin.ModelAdmin):
    list_display = ('id','name','color','memory','ga_url','gs_url',)
    list_editable = ('color','memory','name','ga_url','gs_url',)
    action_form = DuplicateActionForm
    # actions = [duplicate,]

admin.site.register(Product,ProductAdmin)

When actions attribute of ProductAdmin class is not commented, I can duplicate objects. The problem is that I can't delete them. When I check row and select delete selected, it says: No action selected.

This is caused by line:

action_form = DuplicateActionForm

because if actions = [duplicate,] is commented, I can't delete objects correctly until I comment action_form = DuplicateActionForm

Do you know where is the problem?

Upvotes: 3

Views: 2200

Answers (1)

Akshar Raaj
Akshar Raaj

Reputation: 15211

You should add required=False on your custom form field. After that everything would work as expected.

class DuplicateActionForm(ActionForm):
    number = forms.IntegerField(required=False)

Upvotes: 4

Related Questions