Skip to content

Instantly share code, notes, and snippets.

@elcolie
Created September 26, 2017 12:09
Show Gist options
  • Save elcolie/7f097642c4a752e76044c6938c49e097 to your computer and use it in GitHub Desktop.
Save elcolie/7f097642c4a752e76044c6938c49e097 to your computer and use it in GitHub Desktop.
serializers.py
from soken_web.apps.uploaded_files.models import CustomerFromExcel
from rest_framework import serializers
class ModelControllerSerializer(serializers.ModelSerializer):
class Meta:
abstract = True
def create(self, validated_data):
user = self.context['request'].user
validated_data['created_user'] = user
validated_data['updated_user'] = user
return super().create(validated_data)
def update(self, instance, validated_data):
user = self.context['request'].user
validated_data['updated_user'] = user
return super().update(instance, validated_data)
class CustomerFromExcelSerializer(ModelControllerSerializer):
class Meta:
model = CustomerFromExcel
fields = [
'id',
'file',
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment