[Answer]-Django admin inline warning on new record

1👍

You can use the messages app, but to add a message, you need access to the request object. So, maybe you can override the save_formset method on your ModelAdmin instead, something like:

from django.contrib import messages

class YourAdmin(admin.ModelAdmin):
    inlines = [YourInline]

    def save_formset(self, request, form, formset, change):
        # TODO: check if this is the formset for the right inline 
        formset.save()
        effort = 0.0
        for assignment in formset.cleaned_data:
            if not assignment['DELETE']:
                effort += assignment['effort']
        if effort > form.instance.fte * 100:
            messages.warning(request, "Assignments exceed FTE equivalent")
👤sk1p

Leave a comment