Django Admin Custom Add

Say I have a model called Book:

class Book(EOModel):
    title = models.CharField(max_length=100, null=False, blank=False)
    subtitle = models.CharField(max_length=100, null=True, blank=True)
    open_library_key = models.CharField(max_length=32, null=True, blank=True)
    ...
    location = models.ForeignKey(Order, null=False, blank=False, on_delete=models.PROTECT)

The Book model has a classmethod to craete an entry using openlibrary ID.

@classmethod
def from_open_library(cls, open_library_key: str, location: Order) -> Self:
    data = open_library_get_book(open_library_key)
    ...
    book.save()
    
    return book

So given a correct openlibrary ID and an Order object from_open_library would create a new entry.

My question is, how can I implement an django admin page for it? Can I add a "add via openlibrary" next to the actual add button? The page has a char field to get the ID and dropdown would list the Orders to select.

Back to Top