Change save method at Admin panel Django

Viewed 83

This is my models.py

from django.db import models

class Post(models.Model):
    html = models.TextField(editable=False)
    thumbnail = models.TextField(editable=False)
    url = models.TextField()

This is admin.py

from django.contrib import admin
from .models import Post

class PostAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        print("Not working")
        othermethod()
        obj.html = "html"
        obj.save()
        super().save_model(request, obj, form, change)
    
def othermethod():
    print("Not working")

admin.site.register(Post)

How can I call a function that do something before I save a Post through Django admin panel, this is what I've been trying so far, but doesn't work at all, Post object is saving at the database without 'html' field and "othermethod() function isn't been called".

0 Answers
Related