[Fixed]-Why isn't reste framework serializer saving these into two different models

1👍

There are two models, so use serializers.Serializer and override save():

class RushSerializer(serializers.Serializer):
    keyword = ...
    u1 = ...
    keyword2 = ...
    u2 = ...

    def save(self):
        keyword = self.validated_data['keyword']
        u1 = self.validated_data['u1']
        keyword2 = self.validated_data['keyword2']
        u2 = self.validated_data['u2']

        Url1.objects.create(keyword=keyword, u1=u1)
        Url2.objects.create(keyword2=keyword2, u2=u2)

See http://www.django-rest-framework.org/api-guide/serializers/#saving-instances

Leave a comment