[Fixed]-Admin action- queryset to apply Many to Many

1👍

you can assign relations sets in django.

def Red(self, request, queryset):
    red_color = Colour.objects.get(colour_name__iexact='Red')
    queryset.update(available_colours=[red_color])

according to your comment and to docs, it seems django doesnot support bulk update for manytomany fields.

you can solve it this way:

def Red(self, request, queryset):
    red_color = Colour.objects.get(colour_name__iexact='Red')
    for car in queryset:
        car.available_colours.add(red_color)

Leave a comment