0

We have something like the following:

class SecondaryItemInline(admin.TabularInline):
    model = SecondaryItem
    form = SecondaryItemForm

class PrimaryItemAdmin(admin.ModelAdmin):
    inlines = SecondaryItemInline,

What I would like to do is to add a custom message to the default Django admin success message from the clean method of SecondaryItemForm. I am seeing how to do this from PrimaryItemAdmin using save_model, but not seeing anything on doing this from an inline form. Any ideas?

meesterguyperson
  • 1,726
  • 1
  • 20
  • 31
  • This is possible using the following https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.message_user - but you need access to the `request` object. You will be able to do this from the inline NOT the form. – vishen Feb 25 '15 at 02:34
  • Yeah, that seems to be the issue. If I discover something while cleaning the inline forms, I need to be able to report it after saving. Really don't understand why they chose not to make the request available in forms. – meesterguyperson Feb 25 '15 at 13:32
  • Haven't found a direct way of doing what I want, but using the following answer, I can duplicate a few things in the save_formset modeladmin method and make it work. Not ideal, but sufficient. http://stackoverflow.com/questions/4548325/django-customizing-the-message-after-a-successful-form-save – meesterguyperson Feb 25 '15 at 14:02

0 Answers0