I have these models for a database of a library:
class Author(models.Model):
...
class Task(models.Model):
... # detailed explanation of how the author collaborated in the book
class BookTask(models.Model):
book = models.ForeignKey(Book)
author = models.ForeignKey(Author)
task = models.ForeignKey(Task)
class Book(models.Model):
authors = models.ManyToManyField(Author, through='BookTask'...)
Everything there works fine, but I would like to specify one of the existing BookTask relationships as the main one. Think of one book where 3 authors have worked in. I would like to assign all 3 to the book and then set 1 of them as the main one.
I've tried this:
class Book(models.Model):
authors = models.ManyToManyField(Author, through='BookTask'...)
author_main = models.ForeignKey(BookTask...)
But then the generated admin webpage doesn't show the expected select choice widget for the author_main field. Any ideas?
(Note: My current solution is adding a boolean field to the BookTask model to specify which one is the main one, and controlling through form validation that one and only one of them for a book is selected. It works, but maybe there is a more elegant solution).