The admin interface appears to want to keep the primary_key numerical, and so breaks if you have set a field as primary_key=True.
Model:
class Airfield(meta.Model):
fields = (
meta.CharField('code', 'airfield code', maxlength=4, primary_key=True),
meta.CharField('name', 'name', maxlength=50),
)
admin = meta.Admin(
fields = (
(None, {'fields': ('code', 'name')}),
),
)
def __repr__(self):
return self.name
Result from trying to add an item through the admin interface:
There's been an error:
Traceback (most recent call last):
File "/sw/lib/python2.3/site-packages/django/core/handlers/wsgi.py", line 190, in get_response
return callback(request, **param_dict)
File "/sw/lib/python2.3/site-packages/django/views/admin/main.py", line 769, in add_stage
log.log_action(request.user.id, opts.get_content_type_id(), getattr(new_object, opts.pk.name), repr(new_object), log.ADDITION)
File "/sw/lib/python2.3/site-packages/django/models/auth.py", line 293, in _module_log_action
e.save()
File "/sw/lib/python2.3/site-packages/django/core/meta.py", line 57, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))
File "/sw/lib/python2.3/site-packages/django/core/meta.py", line 748, in method_save
(opts.db_table, ','.join(field_names), ','.join(placeholders)), db_values)
File "/sw/lib/python2.3/site-packages/django/core/db/base.py", line 10, in execute
result = self.cursor.execute(sql, params)
ProgrammingError: ERROR: invalid input syntax for integer: "EGKR"
INSERT INTO auth_admin_log (action_time,user_id,content_type_id,object_id,object_repr,action_flag,change_message) VALUES ('2005-07-19 01:31:40',1,17,'EGKR','Redhill',1,'')