0

When using django mailer (https://github.com/pinax/django-mailer) I realized that the default tables added to the admin area (such as Message logs and Messages) did not add the message_log field which indeed is available if one looks at the tables that are added.

Since the error message is very valuable to me I wanted to add it, and simply added the "log_message" to the app's MessageLogAdmin like this:

class MessageLogAdmin(MessageAdminMixin, admin.ModelAdmin):

    list_display = ["id", show_to, "subject", "message_id", "when_attempted", "result", "log_message"]
    list_filter = ["result"]
    date_hierarchy = "when_attempted"
    readonly_fields = ['plain_text_body', 'message_id']
    search_fields = ['message_id']

However, is there really no other way to customize the admin area for django-mailer other than modifying the source code? E.g through settings.py

Thorvald
  • 546
  • 6
  • 18

1 Answers1

1

No you can't do that via settings.py

If I understand correctly, you don't want to fork the app just to edit admin.py, but rather keep it in the requirements.txt file. In that case you could do something like:

class MyOwnMessageLogAdmin(MessageAdminMixin, admin.ModelAdmin):

    list_display = ["id", show_to, "subject", "message_id", "when_attempted", "result", "log_message"]
    list_filter = ["result"]
    date_hierarchy = "when_attempted"
    readonly_fields = ['plain_text_body', 'message_id']
    search_fields = ['message_id']

admin.site.unregister(MessageLog)
admin.site.register(MessageLog, MyOwnMessageLogAdmin)
fekioh
  • 894
  • 2
  • 9
  • 22
  • 1
    ... but then again where would that code live is another matter. You would either have to make a local app just for this, or put this in some other app's `admin.py` – fekioh Dec 29 '20 at 22:31
  • That's exactly what concerns me, it seems a bit overkill to fork the entire app just to add a string of text. I guess I was hoping for some additional settings being available. However, I think the alternative you provided is good enough for me (I'll just include it in one of my admin.py-files). – Thorvald Dec 30 '20 at 13:45
  • yes, I have resorted to this solution myself at times, as I prefer not to fork apps unless I absolutely have to. So as to be able to easily update upon new releases etc. As for the code, putting it in a random app seems weird. In big projects I often have an "extensions" app for such things or you can make a "mailer-extension" app with only an admin.py – fekioh Dec 30 '20 at 16:19