Django - use same column for two foreign keys
<p>I have three models:</p>

<pre><code>class UserProfile:
   user_id = OneToOneField(User, related_name='profile')
   name = CharField

class User:
   # standard django model

class Channel:
   owner = ForeignKey(User)
</code></pre>

<p>And now, I want to get channels filtering on user name. So what I can do is:</p>

<pre><code>Channel.objects.filter(owner__profile__name__icontains='foo')
</code></pre>

<p>But this joins User table and then joins UserProfile, which is not the best, because I would like to join UserProfile table on user_id instead (I would have one join instead of two)</p>

<p>I tried to add another foreign key to model like this:</p>

<pre><code>class Channel:
    owner = models.ForeignKey(
        User,
        db_column='owner_id',
    )
    owner_profile = models.ForeignKey(
        UserProfile,
        db_column='owner_id',
        to_field='user_id')
</code></pre>

<p>But Django doesnt like it....</p>

<pre><code>posts.Post: (models.E007) Field 'owner_profile' has column name 'owner_id' that is used by another field.
    HINT: Specify a 'db_column' for the field.
</code></pre>

<p>Is there any clean workaround for this?</p>