diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2007-09-20 01:55:53 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2007-09-20 01:55:53 +0000 |
| commit | 94c320d8a982ce30f6dd4e7556f2696229b761c7 (patch) | |
| tree | 165ff89b8b262118430ea2f7c1d26cc5af864c09 /tests/modeltests | |
| parent | 28a4aa6f49b11881d43a585f118a3d0537ba9084 (diff) | |
queryset-refactor: Merged to [6381]
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6382 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests')
| -rw-r--r-- | tests/modeltests/basic/models.py | 5 | ||||
| -rw-r--r-- | tests/modeltests/custom_pk/models.py | 9 | ||||
| -rw-r--r-- | tests/modeltests/fixtures/models.py | 9 |
3 files changed, 22 insertions, 1 deletions
diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py index 0a09579761..58770ef2ce 100644 --- a/tests/modeltests/basic/models.py +++ b/tests/modeltests/basic/models.py @@ -33,6 +33,11 @@ __test__ = {'API_TESTS': """ >>> a.id 1L +# Models have a pk property that is an alias for the primary key attribute (by +# default, the 'id' attribute). +>>> a.pk +1L + # Access database columns via Python attributes. >>> a.headline 'Area man programs in Python' diff --git a/tests/modeltests/custom_pk/models.py b/tests/modeltests/custom_pk/models.py index 375859c897..381d81b987 100644 --- a/tests/modeltests/custom_pk/models.py +++ b/tests/modeltests/custom_pk/models.py @@ -56,6 +56,15 @@ DoesNotExist: Employee matching query does not exist. >>> Employee.objects.filter(pk__in=['ABC123','XYZ456']) [<Employee: Fran Bones>, <Employee: Dan Jones>] +# The primary key can be accessed via the pk property on the model. +>>> e = Employee.objects.get(pk='ABC123') +>>> e.pk +u'ABC123' + +# Or we can use the real attribute name for the primary key: +>>> e.employee_code +u'ABC123' + # Fran got married and changed her last name. >>> fran = Employee.objects.get(pk='XYZ456') >>> fran.last_name = 'Jones' diff --git a/tests/modeltests/fixtures/models.py b/tests/modeltests/fixtures/models.py index a1e2446e56..5b53115733 100644 --- a/tests/modeltests/fixtures/models.py +++ b/tests/modeltests/fixtures/models.py @@ -9,6 +9,7 @@ FIXTURE_DIRS setting. """ from django.db import models +from django.conf import settings class Article(models.Model): headline = models.CharField(max_length=100, default='Default headline') @@ -53,7 +54,13 @@ __test__ = {'API_TESTS': """ # object list is unaffected >>> Article.objects.all() [<Article: XML identified as leading cause of cancer>, <Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker on TV is great!>, <Article: Python program becomes self aware>] +"""} +# Database flushing does not work on MySQL with the default storage engine +# because it requires transaction support. +if settings.DATABASE_ENGINE not in ('mysql', 'mysql_old'): + __test__['API_TESTS'] += \ +""" # Reset the database representation of this app. This will delete all data. >>> management.call_command('flush', verbosity=0, interactive=False) >>> Article.objects.all() @@ -75,7 +82,7 @@ Multiple fixtures named 'fixture2' in '...fixtures'. Aborting. # Dump the current contents of the database as a JSON fixture >>> management.call_command('dumpdata', 'fixtures', format='json') [{"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}] -"""} +""" from django.test import TestCase |
