2009/10/13 Daniel Roseman <dan...@roseman.org.uk>

>
> On Oct 13, 11:55 am, DrKJam <drk...@gmail.com> wrote:
> > Hi,
> >
> > I'm following the advice here :-
> >
> > http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/
> >
> > to try and add a custom action to the list display of one of my models in
> > the admin interface.
> >
> > Sadly, as hard as I try, the option is not appearing in the drop down
> list.
> > Anyone else have this problem and is there a way for me to try and
> diagnose
> > the problem?
> >
> > I'm running the official Django 1.1 version.
> >
> > Regards,
> >
> > David Moss
>
> We can't help you unless you show us what you're actually doing. Post
> some code.
>

Here's a cut down example version of what I'm doing. List view is fine and
working as expected, but "Action" drop down list only contains "Delete
selected tests" as a single option. Based on the following, I would also
expect "sets foo='bar'" and "sets foo='baz'" to be available.

models.py
---------------

from django.db import models
from django.contrib import admin

def custom_action1(modeladmin, request, queryset):
    queryset.update(foo='bar')
custom_action1.short_description = "sets foo='bar'"

def custom_action2(modeladmin, request, queryset):
    queryset.update(foo='baz')
custom_action2.short_description = "sets foo='baz'"

class Test(models.Model):
    foo = models.CharField(max_length=30)

    class Meta:
        db_table = 'test'

    def __unicode__(self):
        return self.foo

class TestAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, { 'fields': ('foo',) }),
    )

    list_display = ('foo',)
    list_display_links = ('foo',)
    ordering = ('foo',)
    search_fields = ('foo',)
    actions = ('custom_action1', 'custom_action2')

admin.site.register(Test, TestAdmin)


> --
> DR.
> >
>

--~--~---------~--~----~------------~-------~--~----~
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