In Django admin interface, Is to possible to exclude some of the fields in Inline?
2 Answers
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']
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)
exclude
option, that is.