title: if...else statement inside django model
body: <p>I have a situation on my django project where i need to use an if statement inside a model.py. One of the apps will allow users to create metadata for a document in the other app. So first i create "Metadata" class  that stores its name, label and fieldtype, which is a choice field. On another class (MetadataValues) i create a ForeignKey to Metadata class and an if statement that return a charfield if "fieldtype" inside the "Metadata" class is "text (0)" or return a datefield if "fieldtype" is "date (1)". Is there a way to do this?, im new into programming so i don't know all the logic behind.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>class Metadata(models.Model)
      name = models.CharField(max_length=100, unique=True)
      label = models.CharField(max_length=100)
      METADATA_FIELD_TYPE = (
          ('0', 'Text'),
          ('1', 'Date'),
      )
      fieldtype = models.CharField(max_length=1, choices=METADATA_FIELD_TYPE, default='0')
  
      def __unicode__(self):
          return (self.label)
  
  
  class MetadataValue(models.Model)
      metadata = models.ForeignKey(Metadata)
      if metadata.fieldtype == '0'
          value = models.CharField(max_length=100)
      else
          value = models.DateField(auto_now=False, auto_now_add=False)
  
      def __unicode__(self):
          return (self.metadata.label)
  
  
  class Document(models.Model)
      name = models.CharField(max_length=100, unique=True)
      metadata = models.ManyToManyField(MetadataValue)
  
      def __unicode__(self):
          return (self.name)
  </code></pre>