Hello,

I am attempting to add dynamic actions to the admin actions list. Using
the code below, the dynamic actions are added, but when I run any of the
dynamic ones, I am getting the error:

_set_ACCOUNT() got multiple values for keyword argument 'accountnum'


I know I'm doing something wrong, but I'm not sure what it is. Thanks
for any help you can give me with this.

-J



class TransactionAdmin(admin.ModelAdmin):
    list_display = ('amount', 'memo', 'date')
    list_filter = ('entity', 'account', 'category', 'date')
    ordering = ('-date',)
    search_fields = ('memo','reference', 'date')
    actions = ['setaccountone', 'clearaccount', 'csvexport']

    def clearaccount(self, request, queryset):
        rows_updated = queryset.update(account=None)
        if rows_updated == 1:
            message_bit = "1 record was"
        else:
            message_bit = "%s records were" % rows_updated
        self.message_user(request, "%s changed." % message_bit)
    clearaccount.short_description = "Clear account"

#example
    def set_acct_to_1(self, request, queryset):
        rows_updated = queryset.update(account_id=1)
        if rows_updated == 1:
            message_bit = "1 record was"
        else:
            message_bit = "%s records were" % rows_updated
        self.message_user(request, "%s changed." % message_bit)

    def _set_ACCOUNT(self, request, qs, accountnum, *args, **kwargs):
        rows_updated = qs.update(account_id=accountnum)
        if rows_updated == 1:
            message_bit = "1 record was"
        else:
            message_bit = "%s records were" % rows_updated
        self.message_user(request, "%s changed." % message_bit)
    _set_ACCOUNT.short_description = "Set to account x"

    def get_actions(self, request):
        actions = super(TransactionAdmin, self).get_actions(request)
        accounts = TransactionAccount.objects.all()
        for accountitem in accounts:
            accountnumber = accountitem.pk
            funcname = 'set_acct_to_%s' % accountnumber
            actions.update({funcname:( curry(self._set_ACCOUNT,
accountnum=accountnumber), funcname, "Set to Account: %s" %
accountitem.name)})
        return actions



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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