Django: GenericForeignKey and unique_together : <p>In the application I'm working on I'm trying to share access tokens within a company. Example: a local office can use the headquarter's tokens to post something on their Facebook page.</p>

<pre><code>class AccessToken(models.Model):
    """Abstract class for Access tokens."""
    owner = models.ForeignKey('publish.Publisher')
    socialMediaChannel = models.IntegerField(
        choices=socialMediaChannelList, null=False, blank=False
    )
    lastUpdate = models.DateField(auto_now=True)

    class Meta:
        abstract = True
</code></pre>

<p>Since Facebook, Twitter and other social media sites handle access tokens in their own way I made and abstract class AccessToken. Each site gets its own class e.g. </p>

<pre><code>class FacebookAccessToken(AccessToken):
    # class stuff
</code></pre>

<p>After doing some reading I found out that I must use a <code>GenericForeignKey</code> to point to classes that inherit <code>AccessToken</code>. I made the following class:</p>

<pre><code>class ShareAccessToken(models.Model):
    """Share access tokens with other publishers."""
    sharedWith = models.ForeignKey('publish.Publisher')
    sharedBy = models.ForeignKey(User)

    # for foreignkey to abstract model's children
    contentType = models.ForeignKey(ContentType)
    objectId = models.PositiveIntegerField()
    contentObject = GenericForeignKey('contentType', 'objectId')

    class Meta:
        unique_together = (('contentObject', 'sharedWith'))
</code></pre>

<p>When I run the django test server I get the following error:</p>

<blockquote>
  <p>core.ShareAccessToken: (models.E016) 'unique_together' refers to field
  'contentObject' which is not local to model 'ShareAccessToken'.   HINT:
  This issue may be caused by multi-table inheritance.</p>
</blockquote>

<p>I don't understand why I get this error, first time using <code>GenericForeignKey</code>. What am I doing wrong?</p>

<p>If there is a smarter way to share the access tokens I would love to hear about it.</p>
