PageRenderTime 111ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/modeltests/get_or_create/models.py

https://code.google.com/p/mango-py/
Python | 21 lines | 7 code | 0 blank | 14 comment | 1 complexity | f0ccb130919defb066ad4ac16c96ec3b MD5 | raw file
Possible License(s): BSD-3-Clause
  1. """
  2. 33. get_or_create()
  3. ``get_or_create()`` does what it says: it tries to look up an object with the
  4. given parameters. If an object isn't found, it creates one with the given
  5. parameters.
  6. """
  7. from django.db import models, IntegrityError
  8. class Person(models.Model):
  9. first_name = models.CharField(max_length=100)
  10. last_name = models.CharField(max_length=100)
  11. birthday = models.DateField()
  12. def __unicode__(self):
  13. return u'%s %s' % (self.first_name, self.last_name)
  14. class ManualPrimaryKeyTest(models.Model):
  15. id = models.IntegerField(primary_key=True)
  16. data = models.CharField(max_length=100)