title: django-rest-framework: Setting up serializer for foreign key
body: <p>In my model, I have two tables named: <code>Vtable</code> and <code>Vdata</code>. Each virtual table (in <code>Vtable</code>) has entries of virtual data stored in <code>Vdata</code>.</p>
  
  <p>I'm trying to make a view that would show the list of <code>Vdata</code> corresponding to each <code>Vtable</code></p>
  
  <p>My serializer isn't working and I think it's because I'm doing it backwards.
  I think the problem is in this line:
  <code>table_id = serializers.RelatedField(many=True)</code></p>
  
  <p>For reference, I get this error: <code>'Vtable' object is not iterable</code></p>
  
  <p>Here is my models.py:</p>
  
  <pre><code>from django.db import models
  from django.contrib.auth.models import User
  
  class Vtable(models.Model):
      user = models.ForeignKey(User)
      table_name = models.CharField(max_length=200)
      added_date = models.DateTimeField('date added')
      def __unicode__(self):
          return self.table_name
  
  class Vdata(models.Model):
      table_id = models.ForeignKey(Vtable)
      table_pk = models.IntegerField()
      column_1 = models.CharField(max_length=200)
      column_2 = models.CharField(max_length=200)
      added_date = models.DateTimeField('date added')
      def __unicode__(self):
          return str(self.added_date)
  </code></pre>
  
  <p>Here is my serializers.py:</p>
  
  <pre><code>from django.contrib.auth.models import User, Group
  from rest_framework import serializers
  from vtables.models import Vtable, Vdata
  
  class TableSerializer(serializers.HyperlinkedModelSerializer):
      user = serializers.Field(source='user.username')
  
      class Meta:
          model = Vtable
          fields = ('table_name', 'added_date', 'user')
  
  class EntrySerializer(serializers.HyperlinkedModelSerializer):
      table_id = serializers.RelatedField(many=True)
  
      class Meta:
          model = Vdata
          fields = ('table_id', 'table_pk', 'column_1', 'column_2', 'added_date')
  </code></pre>
  
  <p>Here is the view that calls it:</p>
  
  <pre><code>class EntryList(APIView):
      def get(self, request, format=None):
          entries = Vdata.objects.all()
          serializer = EntrySerializer(entries, many=True)
          return Response(serializer.data
  
          class Meta:
              model = Vdata
              fields = ('table_id', 'table_pk', 'column_1', 'column_2', 'added_date')
  </code></pre>