How to remove Add button in Django admin, for specific Model?

django, django-admin, django-models, python

Solution

It is easy, just overload has_add_permission method in your Admin class like so:

class MyAdmin(admin.ModelAdmin):
    def has_add_permission(self, request):
        return False

Problem

I have Django model "AmountOfBooks" that is used just as balance for Book model. If this is not good pattern for database modeling just say so. Anyway AmountOfBooks have two fields: ``` class AmountOfBooks(models.Model): book = models.ForeignKey(Book, editable=False) amount = models.PositiveIntegerField(default=0, editable=False, help_text="Amount of book.") ``` They are set to editable=False, because this model is meant to be edited only by code. Eg. when book is created object for that book in AmountOfBooks is set to 0 and when books are added or taken balance is either increased or decreased. So in this way fields for AmountOfBooks model are not shown when I click on"Add Amount of books" button in Django admin. But I want to remove that button from Django admin just for AmountOfBooks model. How to do it ? UPDATE Continuation of this question is available on How to make Django model just view (read-only) in Django Admin?

Original source

Related problems