equal
deleted
inserted
replaced
|
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) |