parts/django/tests/modeltests/get_or_create/models.py
changeset 69 c6bca38c1cbf
equal deleted inserted replaced
68:5ff1fc726848 69:c6bca38c1cbf
       
     1 """
       
     2 33. get_or_create()
       
     3 
       
     4 ``get_or_create()`` does what it says: it tries to look up an object with the
       
     5 given parameters. If an object isn't found, it creates one with the given
       
     6 parameters.
       
     7 """
       
     8 
       
     9 from django.db import models, IntegrityError
       
    10 
       
    11 class Person(models.Model):
       
    12     first_name = models.CharField(max_length=100)
       
    13     last_name = models.CharField(max_length=100)
       
    14     birthday = models.DateField()
       
    15 
       
    16     def __unicode__(self):
       
    17         return u'%s %s' % (self.first_name, self.last_name)
       
    18 
       
    19 class ManualPrimaryKeyTest(models.Model):
       
    20     id = models.IntegerField(primary_key=True)
       
    21     data = models.CharField(max_length=100)