Dear forum, I’m learning Django and I playing with actions. I have the following Book library scenario (simplified) :
loanchoices = (
('a', 'On Loan'),
('b', 'Overdue'),
('c', 'Available')
)
class Book(models.Model):
title = models.CharField(max_length=200)
author = models.ForeignKey('Author', on_delete=models.SET_NULL, null=True)
summary = models.TextField(max_length=1000, help_text="Enter a brief description of the book")
ID = models.CharField(max_length=200)
class Loans(models.Model):
borrowername = models.CharField(max_length=200)
booksborrowed = models.ManyToManyField(Book, help_text="Select the books for borrow")
loanstatus = models.CharField(max_length=200, choices=loanchoices, default='a')
I’d like to select several books from Django Admin Book Listview and create a new Loans instance based on that selection. That is, an action that redirects to a Loans add form and the booksborrowed field been prepopulated with the previous Book selection.
I tried a lot but I couldn’t get on how to pass the selection to a new instance.
Thanks in advance!
Ale