I am developing api for webapp. At first I used tastypie and switched to django-rest-framework (drf) . Drift seems very easy to me. What I intend to do is create a nested user profile object. My models below
from django.db import models from django.contrib.auth.models import User class nestedmodel(models.Model): info = models.CharField(null=True, blank=True, max_length=100) class UserProfile(models.Model): add_info = models.CharField(null=True, blank=True, max_length=100) user = models.OneToOneField(User) nst = models.ForeignKey(nestedmodel)
I have other models that are related to the "alien". My Serials below
from django.contrib.auth.models import User, Group from rest_framework import serializers from quickstart.models import UserProfile, nestedmodel class NestedSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = nestedmodel fields = ('info', ) class UserSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = User fields = ('url', 'username', 'email', 'groups') class GroupSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Group fields = ('url', 'name') class UserProfileSerializer(serializers.HyperlinkedModelSerializer): user = UserSerializer() nst = NestedSerializer() class Meta: model = UserProfile user = UserSerializer(many=True) nested = NestedSerializer(many=True) fields = ('nst', 'user')
I can override methods like create(self, validated_data): without any problems. But what I want to know is to which method should the response returned by create() goes , or, in other words, Which method calls create() . In tastypie Resources.py this is an override file for implementing custom methods. And Resource.py contains the order in which the method is called. What is a drf file that does the same thing and illustrates a control flow like Resources.py in tastypie ?.
source share