mirror of https://github.com/django/django.git
Added more tests to custom_pk unit-test model
git-svn-id: http://code.djangoproject.com/svn/django/trunk@461 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7bac552069
commit
63e1f3d39c
|
@ -16,13 +16,35 @@ class Employee(meta.Model):
|
||||||
meta.CharField('first_name', maxlength=20),
|
meta.CharField('first_name', maxlength=20),
|
||||||
meta.CharField('last_name', maxlength=20),
|
meta.CharField('last_name', maxlength=20),
|
||||||
)
|
)
|
||||||
|
ordering = ('last_name', 'first_name')
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%s %s" % (self.first_name, self.last_name)
|
return "%s %s" % (self.first_name, self.last_name)
|
||||||
|
|
||||||
API_TESTS = """
|
API_TESTS = """
|
||||||
>>> e = employees.Employee(employee_code='ABC123', first_name='Dan', last_name='Jones')
|
>>> dan = employees.Employee(employee_code='ABC123', first_name='Dan', last_name='Jones')
|
||||||
>>> e.save()
|
>>> dan.save()
|
||||||
>>> employees.get_list()
|
>>> employees.get_list()
|
||||||
[Dan Jones]
|
[Dan Jones]
|
||||||
|
|
||||||
|
>>> fran = employees.Employee(employee_code='XYZ456', first_name='Fran', last_name='Bones')
|
||||||
|
>>> fran.save()
|
||||||
|
>>> employees.get_list()
|
||||||
|
[Fran Bones, Dan Jones]
|
||||||
|
|
||||||
|
>>> employees.get_object(pk='ABC123')
|
||||||
|
Dan Jones
|
||||||
|
>>> employees.get_object(pk='XYZ456')
|
||||||
|
Fran Bones
|
||||||
|
>>> employees.get_object(pk='foo')
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
EmployeeDoesNotExist: Employee does not exist for {'pk': 'foo'}
|
||||||
|
|
||||||
|
# Fran got married and changed her last name.
|
||||||
|
>>> fran = employees.get_object(pk='XYZ456')
|
||||||
|
>>> fran.last_name = 'Jones'
|
||||||
|
>>> fran.save()
|
||||||
|
>>> employees.get_list(last_name__exact='Jones')
|
||||||
|
[Dan Jones, Fran Jones]
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue