I'm trying to add multiple items to a ManyToManyField on Django via actions. The models:
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
website = models.URLField()
class Author(models.Model):
name = models.CharField(max_length=30)
twitter = models.CharField(max_length=20)
class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()
Admin panel
def add_authors(modeladmin, request, queryset):
return HttpResponseRedirect('/add_authors')
@admin.register(Book)
class BookRegister(admin.ModelAdmin):
actions = [add_authors]
I want to redirect the selected items to /add_authors
page where I want to have a template that have the Djagno admin ManyToManyField selector. How can I redirect to /add_authors
with the queryset context?
How can I make it work?
Thanks.