title: create another instance 'B' after saving an instance 'A' automatically
body: <p>i'm using <code>Django 1.7</code> with <code>django_rest_framework 3.0</code> to develop a restful backend for my application.</p>
  
  <p><strong><em>The scenario:</em></strong> On the client the user will authenticate with a social network, say facebook. The <code>token</code> is sent back to the server which creates and stores an instance of <code>Social</code> model. </p>
  
  <p><strong><em>The need:</em></strong> On saving the <code>Social</code> model, I want to <em>automatically</em> create and store an instance of <code>django.contrib.auth.models User</code> model. The data for the <code>User</code> model will be extracted from the social network that the user just authenticated with.</p>
  
  <p><strong><em>My approach #1:</em></strong> Is there some way where I can send a combined json request to my django backend and create independent <code>User</code> and <code>Social</code> instances. I think this would require changing the <code>serializers.py</code> (given below) code. </p>
  
  <p>For example (request sent to my django):</p>
  
  <pre><code>{
  'social':{
    'token':'XYZ',
    'source':'FB',
   },
  'user_details':{
    'first_name':'sahil',
    'last_name':'gandhi',
    'username':'sahilgandhi',
    'email':'sa***com',
    'password':'password',
    'date_of_birth':'01/01/2015'
   }
  }
  </code></pre>
  
  <p><strong><em>My approach #2:</em></strong> I stumbled across a <code>post_save()</code> signal in django's framework. this is my code implementing the post_save() method 
  This doesn't require a combined request like <strong>approach #1</strong> but a simple post request that will be handled by <code>SocialSerializer</code></p>
  
  <pre><code>@receiver(post_save, sender=Social)
  def create_user_after_social_signup(sender, instance, created=False, **kwargs):
  """
  Automatically create a User instance for every Social signup
  :param sender: Social model
  :param instance: Social instance that just got created
  :param created: is new instance created; boolean
  :param kwargs:
  :return:
  """
  if created:
      social = Social.objects.get(pk=instance.id)
  
      # get user details from social (ex: facebook)
      payload={'access_token':social.token}
      url='https://graph.facebook.com/v2.2/me'
      r=requests.get(url, params=payload)
  
      # create user from response using:
      # User.objects.create_superuser()
  </code></pre>
  
  <p>How to do this if facebook's response is this?</p>
  
  <pre><code>  {
    "id": "XYZ", 
    "birthday": "0***4", 
    "email": "sahi***@gmail.com", 
    "first_name": "Sahil", 
    "gender": "male", 
    "last_name": "Gandhi", 
    "link": "https://www.facebook.com/app_sco*******632440/", 
    "location": {
      "id": "1*****2", 
      "name": "M*******a"
    }, 
    "locale": "en_US", 
    "name": "Sahil Gandhi", 
    "timezone": 5.5, 
    "updated_time": "2015****00", 
    "verified": true
  }
  </code></pre>
  
  <p>My current code is as follows:</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class Social(models.Model):
  
  NONE = 'XX'
  FACEBOOK = 'FB'
  GOOGLEPLUS = 'GP'
  TWITTER = 'TW'
  LINKEDIN = 'LI'
  
  SOCIAL_NETWORKS = (
      (NONE, '------'),
      (FACEBOOK, 'Facebook'),
      (TWITTER, 'Twitter'),
      (GOOGLEPLUS, 'Google Plus'),
      (LINKEDIN, 'LinkedIn'),
  )
  
  user = models.OneToOneField(User, related_name='social_owner')
  token = models.CharField(max_length=250)
  # expires_at = models.DateTimeField('token expires at', blank=True, null=True)
  source = models.CharField(max_length=2, choices=SOCIAL_NETWORKS,)
  
  class Meta:
      db_table = 'user_social'
  </code></pre>
  
  <p><strong>serializer.py</strong></p>
  
  <pre><code>class SocialSerializer(serializers.ModelSerializer):
  class Meta:
      model = Social
      fields = ('user', 'token', 'source')
  
  class UserSerializer(serializers.ModelSerializer):
  class Meta:
      model = User
      fields = ('pk', 'first_name', 'last_name', 'username', 'email', 'date_joined')
  </code></pre>
  
  <p><strong>views.py</strong> normal class based view, i.e. <code>APIView</code> for the models: <code>User</code> and <code>Social</code>.</p>
  
  <p><strong><em>Finally:</em></strong>
  I strongly feel that the <strong><em>approach #1</em></strong> is the better way to do it. Just don't know how to go about it. Either way your help is appreciated. </p>