title: Django ForeignKey from multiple objects
body: <p>I'm creating an app where a user can subscribe/follow to different aspects of the site.</p>
  
  <p>I'm building the table which will record all these subscriptions. My initial instinct is to make one Subscription Table, which will list everything that is subscribed to. Here is how I'm planning it now:</p>
  
  <pre><code>class SubscriptionTypeCode(object):
      CITY = '1'
      REGION = '2'
      COUNTRY = '3'
      USER = '4'
  
  SUBSCRIPTION_TYPE_CHOICES = (
      (SubscriptionTypeCode.CITY, 'City'),
      (SubscriptionTypeCode.REGION, 'Region'),
      (SubscriptionTypeCode.COUNTRY, 'Country'),
      (SubscriptionTypeCode.USER, 'User'),
  )
  class Subscription(models.Model):
      subscriber = models.ForeignKey(User, related_name="subscriber")
      subscription_type = models.CharField(max_length=4, choices=SUBSCRIPTION_TYPE_CHOICES)
      subscription_to_user = models.ForeignKey(User, related_name="subscription_to_user", null=True, blank=True)
      subscription_to_city = models.ForeignKey(City, null=True, blank=True)
      subscription_to_country = models.ForeignKey(Country, null=True, blank=True)
      subscription_to_region = models.ForeignKey(Region, null=True, blank=True)
      created = models.DateTimeField(db_index=True, auto_now_add=True)
      cancelled = models.DateTimeField(null=True, blank=True)
  </code></pre>
  
  <p>This should work, but i'm wondering if it's the most efficient way to do this. Each row will have the subscriber ID, then the type choice, and then depending on that, one of the subscription_to columns will have a foreign object.</p>
  
  <p>This is working, but is requiring a lot of if/else statements in the logic. For example</p>
  
  <pre><code>def create_subscription(request, subscription_type, subscription_id):
      subscription = Subscription.create(
          subscriber = request.user,
          subscription_type = subscription_type,
      )
      if subscription_type == SubscriptionTypeCode.REGION:
          region = get_region(subscription_id)
          subscription.subscription_to_region = region
  
      elif subscription_type == SubscriptionTypeCode.CITY:
          city = get_city(subscription_id)
          subscription.subscription_to_city = city
  
      elif subscription_type == SubscriptionTypeCode.COUNTRY:
          country = get_country(subscription_id)
          subscription.subscription_to_country = country
  
      elif subscription_type == SubscriptionTypeCode.USER:
          user = get_user(subscription_id)
          subscription.subscription_to_user = user
  
      subscription.save()
      return subscription
  </code></pre>
  
  <p>Any thoughts on how to simplify this?  Or is this okay?</p>