formfield_for_manytomany exclude

24 views
Skip to first unread message

carlos

unread,
May 29, 2017, 10:49:04 AM5/29/17
to django...@googlegroups.com
Hello,
I am trying to exclude several categories from a m2m, but when I see the widget in my form all still appear, I put the code that I execute when I load the form, the id that I place are the categories that I do not want to appear

def formfield_for_manytomany(self, db_field, request, **kwargs):
        if db_field.name == "category":
            kwargs["queryset"] = Category.objects.exclude(id__in=[2,3,4,5,6]) #this id i like exclude
            print "see queryset"
            print kwargs["queryset"]
        return super(PostAdmin, self).formfield_for_manytomany(db_field,request, **kwargs)

Any suggestions why it is not working
The code to exclude categories ??

thank
Reply all
Reply to author
Forward
0 new messages