How to get Model Choice Field name instead of id in template using django rest framework
<p>I am getting id of choice field in the template.But I want name of the choice field to display. Please review the below files and let me know how to get the name.</p>

<p>here is my models.py</p>

<p>===============================================================</p>

<pre><code>class Posted(models.Model):
    name = models.CharField(_('Posted In'),max_length=255, unique=True)

class Tags(models.Model):
    name = models.CharField(_('Tag Name'),max_length=255, unique=True)

class Blogs(models.Model):
    author = models.ForeignKey(CustomUser)
    title=models.CharField(max_length=100)
    posted=models.ForeignKey(Posted, blank=True)
    tags= models.ManyToManyField(Tags, blank=True)
    content = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
</code></pre>

<p>serializers.py</p>

<hr>

<pre><code>class BlogsSerializer(serializers.ModelSerializer):
    author = AccountSerializer(read_only=True,required=False)
    class Meta:
        model = Blogs
        fields = ('id','author','title','tags','posted','content','created_at','updated_at')
        read_only_fields=('id','created_at','updated_at')

class TagsSerializer(serializers.ModelSerializer):
    name = serializers.SerializerMethodField()   
    class Meta:
        model = Tags 
        fields = ('id','name')
        read_only_fields=('id','name')
class PostedSerializer(serializers.ModelSerializer):
    name = serializers.SerializerMethodField()
    class Meta:
        model = Posted
        fields = ('id','name')
        read_only_fields=('id','name')
</code></pre>

<p>views.py</p>

<hr>

<pre><code>class BlogViewSet(viewsets.ModelViewSet):
    queryset=Blogs.objects.order_by('-created_at')
    serializer_class= BlogsSerializer

    def get_permissions(self):
        if self.request.method in permissions.SAFE_METHODS:
            return (permissions.AllowAny(),)
        return (permissions.IsAuthenticated(),IsAuthorOfBlog(),)

    def perform_create(self,serializer):
        serializer.save(author=self.request.user)

        return super(BlogViewSet,self).perform_create(serializer)

class TagsViewSet(viewsets.ModelViewSet):
    queryset=Tags.objects.all
    serializer_class= TagsSerializer

class PostedViewSet(viewsets.ModelViewSet):
    queryset=Posted.objects.all
    serializer_class= PostedSerializer
</code></pre>

<h1>Template</h1>

<h1><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="row"&gt;
  &lt;div class="col-sm-12"&gt;
    &lt;div class="well"&gt;
      &lt;div class="blog"&gt;
        &lt;div class="blog__meta"&gt;
          &lt;a href="#"&gt;
            +{{ blog.author.first_name }}
          &lt;/a&gt;
        &lt;/div&gt;

        &lt;div class="blog__content"&gt;
          &lt;p&gt;{{ blog.title }}&lt;/p&gt;
          &lt;p&gt;{{ blog.posted}}&lt;/p&gt;
          &lt;p&gt;{{ blog.tags}}&lt;/p&gt;
          &lt;p&gt;{{ blog.content }}&lt;/p&gt;

        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
</h1>

<p>Thanks in advance</p>

<p>What do you mean by choices ? I see no <code>choices</code> in Field kwargs. You can set Choice field by for example:
<code>chairs = models.IntegerField(max_length=255, choices=CHOICES)</code> and where exactly you get id's instead of name ?</p>

python django django-rest-framework