Possible Bug: filter_horizontal not working when formfield_for_manytomany used

128 views
Skip to first unread message

Korey Peters

unread,
Mar 24, 2010, 9:03:11 PM3/24/10
to Django users
Hello.

When I use formfield_for_manytomany in my admin, those fields do not
render with the filter_horizontal JS picker. For example:

# admin.py
class ProjectAdmin( admin.ModelAdmin ):
def formfield_for_manytomany( self, db_field, request, **kwargs ):
if db_field.name == 'categories':
kwargs['queryset'] = Category.objects.filter(
account=request.user.get_profile().account )
return db_field.formfield( **kwargs )
return super( ProjectAdmin,
self ).formfield_for_foreignkey(db_field, request, **kwargs )

filter_horizontal = ( 'categories' )

# models.py
class Category(models.Model):
some_category = models.CharField(max_length=25)

class Project(models.Model):
categories = models.ManyToManyField('Category')
some_project = models.CharField(max_length=25)

Commenting out the 'formfield_for_manytomany' method causes the
filter_horizontal to work again. Am I missing something?

I've searched this mailing list, the bug tracker for
"formfield_for_manytomany" and not had any hits. Google hasn't proved
much help either.

Any help on getting this working would be much appreciated.

Kind regards,
Korey


Reply all
Reply to author
Forward
0 new messages