'Django - Excluding some fields in Inline Admin Interface

In Django admin interface, Is to possible to exclude some of the fields in Inline?



Solution 1:[1]

with exclude you can do it

ex:

class Book(models.Model):
   author = models.ForeignKey(Author)
   title = models.CharField(max_length=100)
   short_description = models.CharField(max_length=200)

class BookInline(admin.TabularInline):
    model = Book
    exclude = ['short_description']

Solution 2:[2]

In addition to Francisco Lavin's answer, you can exclude "short_description" field from your form by using "fields" with "author" and "title" as shown below:

class Book(models.Model):
   author = models.ForeignKey(Author)
   title = models.CharField(max_length=100)
   short_description = models.CharField(max_length=200)

class BookInline(admin.TabularInline):
    model = Book
    fields = ['author', 'title'] # Here

And also by adding "editable=False" to "short_description" field, you can exclude "short_description" field from your form as shown below ("BookInline" class is not needed):

class Book(models.Model):
   author = models.ForeignKey(Author)
   title = models.CharField(max_length=100)             # Here
   short_description = models.CharField(max_length=200, editable=False)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 djvg
Solution 2 Kai - Kazuya Ito