add a custom model method to django admin

You can override the .save_model(…) method [Django-doc] of the ModelAdmin for your Ad model:

from django.contrib import admin

class AdAdmin(admin.ModelAdmin):
    
    # …
    
    def save_model(self, request, obj, form, change):
        super().save_model(request, obj, form, change)
        obj.add_ownership_including_ancestors(request.user.id)

admin.site.register(Ad, AdAdmin)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top