2

I have an article model which has a many-to-many relationship with itself:

class Article(models.Model):
  title = models.CharField(max_length=200)
  authors = models.ManyToManyField(User)
  abstract = models.TextField(max_length=2000, blank=True)
  full_text = models.TextField(blank=True)
  section = models.ManyToManyField(ArticleSection, null=True)
  references = models.ManyToManyField(ArticleReferences, null=True)
  related_articles = models.ManyToManyField("self", null=True)

  def __unicode__(self):
      return self.title

This is for the related_articles field. How would I do this same sort of login in the rest-framework?

class ArticleSerializer(serializers.HyperlinkedModelSerializer):
  authors = AuthorSerializer(many=True,  read_only=True)
  section = ArticleSectionSerializer(many=True,  read_only=True)
  related_articles = ArticleSerializer(many=True,  read_only=True)
  class Meta:
      model = Article
      fields = (
              'title',
              'authors',
              'abstract',
              'full_text',
              'section',
              'related_articles'
              )

I receive an error for ArticleSerializer not being defined. How would I implement the related articles field?

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.