I'm trying to have a print statement appear on the console every time I add data into my Postgres Database (For example "Post succeeded") from the Django admin but no matter where I put print statements (in admin.py or the models) nothing is appearing. I know the data is going through as there is a POST statement that goes through
and the data is in the database.
In your Admin object, you can put a print
statement in the save_model()
method. It sounds like that's where it will best suit you if you want to print something after adding data.
It would look something like this:
class FooAdmin(admin.ModelAdmin):
...
class Meta:
model = Foo
def save_model(self, request, obj, form, change):
print('Post succeeded')
obj.save()
admin.site.register(Foo, FooAdmin)
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.