title: Django Models - How to store fields in a dict
body: <p>I have a fairly simple user-model perfectly working.
  In order to reduce code redundancy, I try to store fields inside a dictory for reasons you can easily guess.</p>
  
  <p>Example:</p>
  
  <pre><code>def get_social_token(self,social_net=""):
     return self.social_dict[social_net]["token"]
  </code></pre>
  
  <p>If I don't do such a structure I must do some "if/then ... elif... else".
  And of course I need to modify my code whenever I decide to add a new social network to my app.</p>
  
  <p>I have tried two different approaches, both of them give me the same result:</p>
  
  <ul>
  <li>No error</li>
  <li>No field is actually detected and created in the DB</li>
  </ul>
  
  <p>I'd like to mention that if I use a "conventional manner" to implement this behaviour such as:</p>
  
  <ul>
  <li>twitter_social_token = EncryptedCharField(max_length=500, default='', blank=True, null=True)</li>
  </ul>
  
  <p>It perfectly works, so it comes from the use of a dictionary.</p>
  
  <p>Any idea to solve this ?
  Btw. I would prefer avoiding using a new model and a foreign key... Only a One-to-One association, I would prefer not having to perform any "join" or select in another table...</p>
  
  <p>Bellow, you'll find the two attempts I made which doesn't work (and I don't know why):</p>
  
  <p><strong>First attempt:</strong></p>
  
  <pre><code>social_fields = {
      'twitter' : {
          'token'  : EncryptedCharField(max_length=500, default='', blank=True, null=True),
          'secret' : EncryptedCharField(max_length=500, default='', blank=True, null=True)
      },
      'facebook' : {
          'token'  : EncryptedCharField(max_length=500, default='', blank=True, null=True),
          'secret' : EncryptedCharField(max_length=500, default='', blank=True, null=True)
      },
      'gplus' : {
          'token'  : EncryptedCharField(max_length=500, default='', blank=True, null=True),
          'secret' : EncryptedCharField(max_length=500, default='', blank=True, null=True)
      },
      'linkedin' : {
          'token'  : EncryptedCharField(max_length=500, default='', blank=True, null=True),
          'secret' : EncryptedCharField(max_length=500, default='', blank=True, null=True)
      },
  }
  </code></pre>
  
  <p><strong>Second attempt:</strong></p>
  
  <pre><code>social_tokens = dict()
  
  social_tokens["twitter"] = dict()
  social_tokens["facebook"] = dict()
  social_tokens["linkedin"] = dict()
  social_tokens["gplus"] = dict()
  
  social_tokens["twitter"]["token"] = EncryptedCharField(max_length=500, default='', blank=True, null=True)
  social_tokens["twitter"]["secret"] = EncryptedCharField(max_length=500, default='', blank=True, null=True)
  
  social_tokens["facebook"]["token"] = EncryptedCharField(max_length=500, default='', blank=True, null=True)
  social_tokens["facebook"]["secret"] = EncryptedCharField(max_length=500, default='', blank=True, null=True)
  
  social_tokens["linkedin"]["token"] = EncryptedCharField(max_length=500, default='', blank=True, null=True)
  social_tokens["linkedin"]["secret"] = EncryptedCharField(max_length=500, default='', blank=True, null=True)
  
  social_tokens["gplus"]["token"] = EncryptedCharField(max_length=500, default='', blank=True, null=True)
  social_tokens["gplus"]["secret"] = EncryptedCharField(max_length=500, default='', blank=True, null=True)
  </code></pre>
  
  <p>Thanks for the help dear friends,</p>
  
  <p>Jonathan</p>