Hi all,
We have a situation where;
1. we have a database that has several tables that use composite
primary keys
2. the database *cannot* be munged to add an auto increment integer
field (sadly, otherwise this would be a very short post)
3. we don't need to write back to the database
4. we don't need these tables to be represented in the admin
application
5. we would lookup records in the table via one or more of the
(primary keyed, therefore indexed) composites of the primary key
6. we need a 'primary key' so we can iterate over the objects that are
returned from queries

so, with that in mind,

can anyone suggest a way of 'creating' the key we need for #6 above?

I had thought of something like this;

# this field does not exist in the database
fake_pk = FakePrimaryKeyField(primary_key = True, composites =
['field1' ,'field2', 'field3'])
# the following fields do exist in the database
field1 = models.CharField(max_length = 10)
field2 = models.CharField(max_length = 5)
field3 = models.IntegerField()

with our 'FakePrimaryKeyField' doing something like;

pk = '%s%s%s' % (field1, field2, field3)

But I can't figure out how to 'tie in' the fields to tell the _meta
part of the model that fake_pk is supposed to be the primary key.

Note that 'fake_pk' is *not* in the database at all.

Does anyone have any pointers; I've looked at
http://code.djangoproject.com/wiki/MultipleColumnPrimaryKeys and
http://docs.djangoproject.com/en/dev/howto/custom-model-fields/ and
examples of 'custom fields' and nothing I've seen seems to add the
vital "I'm the primary key" juice into the mix.

Any pointers will be gratefully accepted!

Cheers,
Tone
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to