Hi,

How can I call a function after a successful POST?

Below a simple contact example I want to run a function called 
contact_added() after a succefull contcat adding/updating.
Sorry for the silly question, I'm still a newbie in Django universe :)

#models.py
from django.db import models

class Contact(models.Model):
    id = models.BigIntegerField(primary_key=True, unique=True)
    mobile = models.BigIntegerField(default=0)
    username = models.CharField(max_length=60, blank=True, null=True)
    first_name = models.CharField(max_length=60, blank=True, null=True)
    last_name = models.CharField(max_length=60, blank=True, null=True)
    
    def __str__(self):
        return str(self.mobile)

  
#views.py
from django.shortcuts import render

from rest_framework import viewsets

from .serializers import ContactSerializer
from .models import Contact


class ContactViewSet(viewsets.ModelViewSet):
    queryset = Contact.objects.all().order_by('mobile')
    serializer_class = ContactSerializer


#serializers.py
from rest_framework import serializers

from .models import Contact

class ContactSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Contact
        fields = ('id', 'mobile', 'username', 'first_name', 'last_name')


-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/c9fb8116-d65b-45a1-a52a-8eff5d106394o%40googlegroups.com.

Reply via email to