Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 0660203afe66fbc663a4e0af93ec74cd61e2c712 1 parent 5b812ae
Adrian Holovaty authored August 10, 2005
2  tests/testapp/models/__init__.py
... ...
@@ -1,3 +1,3 @@
1 1
 __all__ = ['basic', 'repr', 'custom_methods', 'many_to_one', 'many_to_many',
2 2
            'ordering', 'lookup', 'get_latest', 'm2m_intermediary', 'one_to_one',
3  
-           'm2o_recursive', 'm2o_recursive2', 'save_delete_hooks']
  3
+           'm2o_recursive', 'm2o_recursive2', 'save_delete_hooks', 'custom_pk']
28  tests/testapp/models/custom_pk.py
... ...
@@ -0,0 +1,28 @@
  1
+"""
  2
+14. Using a custom primary key
  3
+
  4
+By default, Django adds an ``"id"`` field to each model. But you can override
  5
+this behavior by explicitly adding ``primary_key=True`` to a field.
  6
+
  7
+NOTE: This isn't yet supported. This model exists as a unit test that currently
  8
+fails.
  9
+"""
  10
+
  11
+from django.core import meta
  12
+
  13
+class Employee(meta.Model):
  14
+    fields = (
  15
+        meta.CharField('employee_code', maxlength=10, primary_key=True),
  16
+        meta.CharField('first_name', maxlength=20),
  17
+        meta.CharField('last_name', maxlength=20),
  18
+    )
  19
+
  20
+    def __repr__(self):
  21
+        return "%s %s" % (self.first_name, self.last_name)
  22
+
  23
+API_TESTS = """
  24
+>>> e = employees.Employee(employee_code='ABC123', first_name='Dan', last_name='Jones')
  25
+>>> e.save()
  26
+>>> employees.get_list()
  27
+[Dan Jones]
  28
+"""

0 notes on commit 0660203

Please sign in to comment.
Something went wrong with that request. Please try again.