Friday, October 31, 2014

Re: Primary keys vs. natural keys

Hallöchen!

Carl Meyer writes:

> [...]
>
> There is no built in feature for this, but it doesn't seem like a
> hard problem to solve with your own conventions. For instance,
> rather than hardcoding the name of the natural key field inside
> the natural_key method, make it a model class attribute,
> e.g. MyModel.natural_key_field.

Do you mean this:

class ExternalOperator(models.Model):

name = models.CharField(_("name"), max_length=30, unique=True)
natural_key_field = "name"

It works (at least, it doesn't abort) but I thought only fields were
allowed as attributes.

Tschö,
Torsten.

--
Torsten Bronger Jabber ID: torsten.bronger@jabber.rwth-aachen.de
or http://bronger-jmp.appspot.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8738a4h78e.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment