######from file serilaizers.py###############
from rest_framework import serializers
from .models import Article
# class ArticleSerializer(serializers.Serializer):
# title = serializers.CharField(max_length=120)
# description = serializers.CharField()
# body = serializers.CharField()
# author_id = serializers.IntegerField()
class ArticleSerializer(serializers.ModelSerializer):
class Meta:
model = Article
fields = ('title', 'description', 'body', 'author_id')
def create(self, validated_data):
return Article.objects.create(**validated_data)
# class UserSerializer(serializers.HyperlinkedModelSerializer):
#########from file models.py##############
# from django.db import models
# Create your models here.
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=255)
email = models.EmailField()
class Article(models.Model):
title = models.CharField(max_length=120)
description = models.TextField()
body = models.TextField()
author = models.ForeignKey('Author',on_delete=models.CASCADE,)
def __str__(self):
return self.title
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/424f69bd-4722-4269-914e-de26b978275d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.