I have the models like this:
class Category(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(unique=True, max_length=255, blank=True,default=None)
desc = models.TextField(blank=True, null=True )
...
class Post(models.Model):
title = models.CharField(max_length=255)
pub_date = models.DateTimeField(editable=False,blank=True)
author = models.ForeignKey(User, null=True, blank=True)
categories = models.ManyToManyField(Category, blank=True, through='CatToPost')
...
class CatToPost(models.Model):
post = models.ForeignKey(Post)
category = models.ForeignKey(Category)
...
Here is the serializer:
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = ('name','slug')
class PostSerializer(serializers.ModelSerializer):
categories = CategorySerializer(many=True, required=True)
class Meta:
model = Post
.......
The views.py
class SingleListing(generics.RetrieveUpdateDestroyAPIView):
queryset = Post.objects.all()
serializer_class =Post
Serializer
But this doesn't show the category field in the web-browsable view. I only see the Category label, but the input fields of this fields is not there. What is the problem?
DRF will not support
many=True
and rise thisLists are not currently supported in HTML input.
Category
is not a field it's a model. It will show all the model related fields.Try this:
serializers.py
views.py
Showing the fields in the web-browserview
well, you should write your serializer like this: