0

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.

3
  • 1
    If you need to specify extra data, that is not very trivial. Django's actions typically only work with one (or more) records. Commented Dec 17, 2024 at 12:23
  • So the only solution would be to create custom views? Which TBH is not that complex. Commented Dec 17, 2024 at 16:38
  • no. Move the logic to the model layer. Commented Dec 17, 2024 at 17:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.