django serializer code example
Example 1: serialization in django
serialization in django
from rest_framework import serializers
from .models import Product
class ProductSerializers(serializers.ModelSerializer):
class Meta:
model = Product
fields = '__all__'
Example 2: drf serializer
serializer = CommentSerializer(data={'email': 'foobar', 'content': 'baz'})
serializer.is_valid()
serializer.errors
Example 3: User serializer in django rest framework
class Event(models.Model):
user = models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
date = models.DateTimeField(default=timezone.now)
place = models.CharField(max_length=255)