On Monday, 15 December 2014 11:04:13 UTC, Gerald Klein wrote:
>
>
>
> Daniel,
> I didn't include any code as I didn't do anything unusual but if you think
> that would help here it is.I was hoping that there was some ordinary
> theoretical basis for this as I didn't do anything custom really, aside
> from the id generation for the "Entity" class, which I generate the id
> manually much like an Oracle sequence object, I do this in order to
> facilitate the creation of relationships between arbitrary objects.
>
But that "aside" is of course the entire problem.
class Entity(models.Model):
> """ the fName field is also the company name field """
> id = models.BigIntegerField(primary_key=True, unique=True,
> default=get_entity_id())
>
Leaving aside whatever reasons you have for doing this very odd thing, the
error is clear: you've called the get_entity_id function in the definition,
which means it is executed at first import time, so every instance of
Entity gets the same ID as its default. If you're using a function to
provide a default value, you must always pass the *callable*, like this:
id = models.BigIntegerField(primary_key=True, unique=True,
default=get_entity_id)
ie without the calling brackets.
But I strongly recommend you don't do this. Whatever you mean by
"facilitating the creation of relationships between arbitrary objects",
there is almost certainly a better way to do it in Django.
--
DR.
>
--
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 [email protected].
To post to this group, send email to [email protected].
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/312afeac-a3cf-479b-a544-7f6690732257%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.