django-rest-framework serializer for ContentType object
<p>I am building an activity model, somewhat similar to this <a href="https://github.com/justquick/django-activity-stream" rel="noreferrer">package</a>. It has an actor, verb and the target.</p>

<pre><code>class Activity(models.Model):
    actor_type = models.ForeignKey(ContentType, related_name='actor_type_activities')
    actor_id = models.PositiveIntegerField()
    actor = GenericForeignKey('actor_type', 'actor_id')
    verb = models.CharField(max_length=10)
    target_type = models.ForeignKey(ContentType, related_name='target_type_activities')
    target_id = models.PositiveIntegerField()
    target = GenericForeignKey('target_type', 'target_id')
    pub_date = models.DateTimeField(default=timezone.now)
</code></pre>

<p>Now whenever a new object of whichever models (Tender, Job and News) is created, a new Activity object is created, with the <code>target</code> being the objects of any of these three models.</p>

<blockquote>
  <p>eg. user (actor) published (verb) title (target)</p>
</blockquote>

<pre><code>class Tender(models.Model):
    title = models.CharField(max_length=256)
    description = models.TextField()

class Job(models.Model):
    title = models.CharField(max_length=256)
    qualification = models.CharField(max_length=256)

class News(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL)
    title = models.CharField(max_length=150)
</code></pre>

<p>To get this data I am making an API which will get me the required json data. I am using <a href="http://www.django-rest-framework.org/" rel="noreferrer">django-rest-framework</a> for this and very new with it.</p>

<pre><code>class ActorSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('id', 'username', 'email')

class ActivitySerializer(serializers.HyperlinkedModelSerializer):
    actor = ActorSerializer()
    class Meta:
        model = Activity
        fields = ('url', 'actor', 'verb', 'pub_date')
</code></pre>

<p>In the above serializers, I knew that <code>actor</code> will be the User. And so I used the User model for the <code>ActorSerializer</code> class. But as for the <code>target</code>, it can be any of these three models (News/Job/Tender).</p>

<p>How can I make a serializer (eg. <code>TargetSerialier</code> class) for the ContentType object so that I can use the <code>target</code> in the <code>ActivitySerializer</code> class field?</p>