Ahmed Yasin
Ahmed Yasin

Reputation: 948

How to add check on admin side actions in django?

Here i'm using django latest verion which is 3.1.4 and I just want to add condition in django admin side. I just wanted to return some text in terminal if i update my model from admin panel.

In my case user submit kyc form admin person approved that form user will get notification on approval. (Right now I just want to print some message when admin update his kyc by updating his kyc form by updated approved boolean field.

In short Just wanted to show message when admin updates any model in django admin side.

admin.py

class KycAdmin(admin.ModelAdmin):
    list_display = ['__str__','owner']
    class Meta:
        model = KycModel

    def post(self,request):
        response = "i'm updated"
        print(vu)
        return vu


admin.site.register(KycModel,KycAdmin)

If more detail is require then you can just tell me in a comments.

Upvotes: 0

Views: 94

Answers (1)

Niketan
Niketan

Reputation: 74

Have you tried overriding the save method in models. Whenever you save an object, it will hit the save method. You can print whatever you want to over there

class SomeModel(models.Model):
    ... some fields for eg. name

    def save(self, *args, **kwargs):
        print(self.name)
        
        super().save(*args, **kwargs)

This is the simplest way to achieve it. You can also override save in admin.

Upvotes: 1

Related Questions