Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom_pk unit tests, which fail because of #81
git-svn-id: http://code.djangoproject.com/svn/django/trunk@458 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
1 parent
5b812ae
commit 0660203
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,3 @@ | |||
__all__ = ['basic', 'repr', 'custom_methods', 'many_to_one', 'many_to_many', | __all__ = ['basic', 'repr', 'custom_methods', 'many_to_one', 'many_to_many', | ||
'ordering', 'lookup', 'get_latest', 'm2m_intermediary', 'one_to_one', | 'ordering', 'lookup', 'get_latest', 'm2m_intermediary', 'one_to_one', | ||
'm2o_recursive', 'm2o_recursive2', 'save_delete_hooks'] | 'm2o_recursive', 'm2o_recursive2', 'save_delete_hooks', 'custom_pk'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
""" | |||
14. Using a custom primary key | |||
By default, Django adds an ``"id"`` field to each model. But you can override | |||
this behavior by explicitly adding ``primary_key=True`` to a field. | |||
NOTE: This isn't yet supported. This model exists as a unit test that currently | |||
fails. | |||
""" | |||
|
|||
from django.core import meta | |||
|
|||
class Employee(meta.Model): | |||
fields = ( | |||
meta.CharField('employee_code', maxlength=10, primary_key=True), | |||
meta.CharField('first_name', maxlength=20), | |||
meta.CharField('last_name', maxlength=20), | |||
) | |||
|
|||
def __repr__(self): | |||
return "%s %s" % (self.first_name, self.last_name) | |||
|
|||
API_TESTS = """ | |||
>>> e = employees.Employee(employee_code='ABC123', first_name='Dan', last_name='Jones') | |||
>>> e.save() | |||
>>> employees.get_list() | |||
[Dan Jones] | |||
""" |