1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

magic-removal: Moved model unit tests from 'testapp' package into 'modeltests' package, with each model test getting its own app

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1606 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty
2005-12-12 04:07:46 +00:00
parent 0309650237
commit 9b1dd36665
43 changed files with 0 additions and 5 deletions

View File

@@ -0,0 +1,47 @@
"""
18. Using SQL reserved names
Need to use a reserved SQL name as a column name or table name? Need to include
a hyphen in a column or table name? No problem. Django quotes names
appropriately behind the scenes, so your database won't complain about
reserved-name usage.
"""
from django.core import meta
class Thing(meta.Model):
when = meta.CharField(maxlength=1, primary_key=True)
join = meta.CharField(maxlength=1)
like = meta.CharField(maxlength=1)
drop = meta.CharField(maxlength=1)
alter = meta.CharField(maxlength=1)
having = meta.CharField(maxlength=1)
where = meta.CharField(maxlength=1)
has_hyphen = meta.CharField(maxlength=1, db_column='has-hyphen')
class META:
db_table = 'select'
def __repr__(self):
return self.when
API_TESTS = """
>>> t = Thing(when='a', join='b', like='c', drop='d', alter='e', having='f', where='g', has_hyphen='h')
>>> t.save()
>>> print t.when
a
>>> u = Thing(when='h', join='i', like='j', drop='k', alter='l', having='m', where='n')
>>> u.save()
>>> print u.when
h
>>> Thing.objects.get_list(order_by=['when'])
[a, h]
>>> v = Thing.objects.get_object(pk='a')
>>> print v.join
b
>>> print v.where
g
>>> Thing.objects.get_list(order_by=['select.when'])
[a, h]
"""