Email model class
class Email(models.Model)
body_message = models.TextField(max_length = 256, null = False)
#other fields ForeignKey, subject, to etc.
Tabular Inline model.
#Inline Email
class EmailInline(admin.TabularInline):
model = Email
And this is my RequestAdmin model that shows inlines.
class RequestAdmin(admin.ModelAdmin):
inlines = [EmailInline,]
#In change_view() i want to print my inlines properties
def change_view(self, request, object_id, form_url='', extra_context=None):
for inline in self.inlines:
#Here i can remove my specific inline
self.inlines.remove(inline)
#But i want to check my inline_class properties
print(inline.body_message) #This line raise exception
#i want to print inlines body_message
return super(RequestAdmin, self).change_view(request, object_id)
Error image which i am getting.
Exception Value:
type object 'EmailInline' has no attribute 'body_message'
I think I understand your question a bit better - you want to affect the actual objects that are being populated into the inline form(s), and hide certain ones based on the contents of the
body_message
property. In that case, you can override theInlineModelAdmin.get_queryset
method, which will give you the opportunity to exclude certain items; or theModelAdmin.get_inline_formsets
method, which gives you the opportunity to alter the forms that will be generated for the inline objects: