简体   繁体   中英

How can i print new instance in console after creating a post request from django admin panel

When I post data from Django admin panel. I want to print data always in the console when new instance created from Django admin panel

You can override save_model method on admin.

from django.contrib import admin

class ArticleAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        obj.user = request.user
        print(obj)
        super().save_model(request, obj, form, change)

Reference: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM