/tests/modeltests/get_or_create/models.py
Python | 21 lines | 7 code | 0 blank | 14 comment | 0 complexity | f0ccb130919defb066ad4ac16c96ec3b MD5 | raw file
Possible License(s): BSD-3-Clause
1""" 233. get_or_create() 3 4``get_or_create()`` does what it says: it tries to look up an object with the 5given parameters. If an object isn't found, it creates one with the given 6parameters. 7""" 8 9from django.db import models, IntegrityError 10 11class 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 19class ManualPrimaryKeyTest(models.Model): 20 id = models.IntegerField(primary_key=True) 21 data = models.CharField(max_length=100)