title: Django Rest Framework: How to do nested serialization with ContentType
body: <p>I have an application that has a Company, and this company can have 0 or multiple addresses. Companies are not the only 'models' that could have addresses. To achieve this, I use ContentTypes.</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class Company(models.Model):
  ''' models a company in the system. '''
  
      number = models.CharField(_('Number'), unique=True, max_length=20)
      name = models.CharField(_('Name'), max_length=100)
      active = models.BooleanField(_('Active'), default=True)
  
      def _get_addresses(self):
          '''
          '''
          contentType = ContentType.objects.get(
              model=self.__class__.__name__.lower()
          )
          try:
              addresses = Address.objects.get(
                  actor_type=contentType, actor_id=self.id
              )
          except Address.DoesNotExist:
              addresses = []
          return addresses
      addresses = property(_get_addresses)
  
  class Address(Auditable):
      ''' models an address '''
  
      actor_type = models.ForeignKey(ContentType)
      actor_id = models.PositiveIntegerField()
      actor_object = fields.GenericForeignKey('actor_type', 'actor_id')
      _type = models.CharField(
          _('Address Type'), 
          max_length=10,
          choices=sorted(TYPES.items())
      )
      active = models.BooleanField(default=True)
      address1 = models.CharField(_('Address 1'), max_length=50)
      address2 = models.CharField(
          _('Address 2'),
          max_length=50,
  ...
  </code></pre>
  
  <p>This way, I could also have a Profile model and I could link multiple addresses to a Profile. However, my problem comes when I tried to implement the Serializers.</p>
  
  <p><strong>Serializers.py</strong></p>
  
  <pre><code>class AddressSerializer(serializers.ModelSerializer):
      class Meta:
          model = Address
          fields = (
              '_type',
              'address1',
              'address2',
              'address3',
              'country',
              'state',
              'city'
          )
  
  class CompanySerializer(serializers.ModelSerializer):
  
      addresses = AddressSerializer(required=False, many=True)
  
      class Meta:
          model = Company
          fields = (
              'number',
              'name',
              'addresses'
          )
  </code></pre>
  
  <p>This implementation gives me this <a href="https://i.stack.imgur.com/opBt9.jpg" rel="nofollow noreferrer">error</a>. It says that it cannot iterate through Address model (which makes sense), but I'm not sure how to make my addresses iterable.</p>
  
  <p>I would need to perform CRUD operations not only on the Company, but also on the nested Address<strong>es</strong>.</p>
  
  <p>Any suggestions/ideas on how to go about this?</p>