Esempio n. 1
0
class ArticleSerializer(serializers.Serializer):
    id = serializers.IntegerField(read_only=True)
    author = serializers.CharField()
    title = serializers.CharField()
    description = serializers.CharField()
    body = serializers.TextField()
    location = serializers.CharField()
    publication_date = serializers.DateField()
    active = serializers.BooleanField()
    created_at = serializers.DateTimeField(read_only=True)
    updated_at = serializers.DateTimeField(read_only=True)

    def create(self, validated_data):
        print(validated_data)
        return Article.objects.create(**validated_data)

    def update(self, instance, validated_data):
        instance.author = validated_data.get("author", instance.author)
        instance.title = validated_data.get("title", instance.title)
        instance.description = validated_data.get("description", instance.description)
        instance.body = validated_data.get("body", instance.body)
        instance.location = validated_data.get("location", instance.location)
        instance.publication_date = validated_data.get("author", instance.publication_date)
        instance.active = validated_data.get("author", instance.active)
        instance.save()
        return instance
Esempio n. 2
0
class relevantAPISerializer(serializers.Serializer):
    id = serializers.CharField(required=True, allow_blank=False, default='')
    name = serializers.CharField(required=True, allow_blank=False, default='')
    description = serializers.TextField(required=False, allow_blank=True,default='')
    context = serializers.CharField(required=False, allow_blank=True, default='')
    version = serializers.CharField(required=False, allow_blank=True, default='')
    provider = serializers.CharField(required=False, allow_blank=True, default='')
    status = serializers.CharField(required=False, allow_blank=True, default='')

    def create(self, validated_data):
        """
        Create and return a new `API` instance, given the data.
        """
        return API.objects.create(**validated_data)

    def update(self, instance, validated_data):
        """
        Update and return an existing `API` instance, given the validated data.
        """
        instance.id = validated_data.get('id', instance.id)
        instance.name = validated_data.get('name', instance.name)
        instance.description = validated_data.get('description', instance.description)
        instance.context = validated_data.get('context', instance.context)
        instance.version = validated_data.get('version', instance.version)
        instance.provider = validated_data.get('provider', instance.provider)
        instance.status = validated_data.get('status', instance.status)
        instance.tags = models.TextField('tags', instance.tags)
		instance.apiDefinition = models.TextField('apiDefinition', instance.apiDefinition)
		instance.endpointURLs = models.TextField('endpointURLs', instance.endpointURLs)
		instance.businessInformation = models.TextField('businessInformation', instance.businessInformation)
		instance.keywords = models.TextField('keywords', instance.keywords)
        instance.save()
        return instance
Esempio n. 3
0
class TextEntrySerializer(serializers.Serializer):
    id = serializers.IntegerField()
    text = serializers.TextField(max_length=10000)
    tone = serializers.CharField(max_length=255)
    emotion = serializers.CharField(max_length=255)
    professionalism = serializers.IntegerField()
    offensiveness = serializers.CharField(max_length=255)
    reading_level = serializers.IntegerField()

    def create(self, validated_data):
        return TextEntry.objects.create(**validated_data)
Esempio n. 4
0
class PostSerializer(serializers.ModelSerializer):
    student = StudentSerializer()
    description = serializers.TextField()
    datetime = serializers.DateTimeField()
    class Meta:
        model = models.Post
        fields = "__all__"

    def create(self, validated_data):
        return models.Post.objects.create(**validated_data)

    def update(self, instance, validated_data):
        instance.student = validated_data.get('student', instance.student)
        instance.description = validated_data.get('description', instance.description)
        instance.datetime = validated_data.get('datetime', instance.datetime)
        instance.save()
        return instance
Esempio n. 5
0
class PostSerializer(serializers.ModelSerializer):
    id = serializers.IntegerField(read_only=True)
    title = serializers.CharField()
    body = serializers.TextField()
    created_at = serializers.DateTimeField(read_only=True)
    like_count = serializers.IntegerField()
    created_by = serializes.ForeignKey()
    list = PostListSerializer(read_only=True)

    class Meta:
        model = Post
        fields = (
            'id',
            'title',
            'body',
            'created_at',
            'created_by',
            'like_count',
            'list',
        )
Esempio n. 6
0
class CompanySerializer(serializers.Serializer):
    company_id = serializers.AutoField(primary_key=True)
    company_name = serializers.TextField()

    def create(self, validated_data):
        """
        Create and return a new `Snippet` instance, given the validated data.
        """
        return Snippet.objects.create(**validated_data)

    def update(self, instance, validated_data):
        """
        Update and return an existing `Snippet` instance, given the validated data.
        """
        instance.company_id = validated_data.get('company_id',
                                                 instance.company_id)
        instance.company_name = validated_data.get('name',
                                                   instance.company_name)

        instance.save()
        return instance