~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to tests/modeltests/basic/models.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
This is a basic model with only two non-primary-key fields.
6
6
"""
7
 
# Python 2.3 doesn't have set as a builtin
8
 
try:
9
 
    set
10
 
except NameError:
11
 
    from sets import Set as set
12
 
 
13
 
# Python 2.3 doesn't have sorted()
14
 
try:
15
 
    sorted
16
 
except NameError:
17
 
    from django.utils.itercompat import sorted
18
 
 
19
 
from django.db import models
 
7
from django.db import models, DEFAULT_DB_ALIAS
20
8
 
21
9
class Article(models.Model):
22
10
    headline = models.CharField(max_length=100, default='Default headline')
211
199
>>> Article.objects.get(id__exact=8) == Article.objects.get(id__exact=7)
212
200
False
213
201
 
 
202
# You can use 'in' to test for membership...
 
203
>>> a8 in Article.objects.all()
 
204
True
 
205
 
 
206
# ... but there will often be more efficient ways if that is all you need:
 
207
>>> Article.objects.filter(id=a8.id).exists()
 
208
True
 
209
 
214
210
# dates() returns a list of available dates of the given scope for the given field.
215
211
>>> Article.objects.dates('pub_date', 'year')
216
212
[datetime.datetime(2005, 1, 1, 0, 0)]
365
361
 
366
362
building_docs = getattr(settings, 'BUILDING_DOCS', False)
367
363
 
368
 
if building_docs or settings.DATABASE_ENGINE == 'postgresql':
 
364
if building_docs or settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] == 'django.db.backends.postgresql':
369
365
    __test__['API_TESTS'] += """
370
366
# In PostgreSQL, microsecond-level precision is available.
371
367
>>> a9 = Article(headline='Article 9', pub_date=datetime(2005, 7, 31, 12, 30, 45, 180))
374
370
datetime.datetime(2005, 7, 31, 12, 30, 45, 180)
375
371
"""
376
372
 
377
 
if building_docs or settings.DATABASE_ENGINE == 'mysql':
 
373
if building_docs or settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] == 'django.db.backends.mysql':
378
374
    __test__['API_TESTS'] += """
379
375
# In MySQL, microsecond-level precision isn't available. You'll lose
380
376
# microsecond-level precision once the data is saved.