Hallöchen!
Do I understand it correctly that in the Django community, it is
preferred to use surrogate primary keys (the auto ID field) instead
of explicitly setting primary keys? Currently, I add natural_key()
methods to many of my models, but some of them return only one
field. Now I wonder whether I made a mistake and should have chosen
that field as the primary key.
My use case is that I need to retrieve the natural keys of all
objects in the database of a particular model. As far as I can see,
this can only be achieved by fetching all objects and calling the
natural_key() method for all of them. In contrast,
model.objects.values_list("pk", flat=True)
is probably *much* faster.
Is it possibly to specify a single field a natural key somehow
(besides making it the PK)? For example, it is possible to add a
Meta attribute to the model?
Tschö,
Torsten.
--
Torsten Bronger Jabber ID:
torsten...@jabber.rwth-aachen.de
or
http://bronger-jmp.appspot.com