Hi,

It's probably better to handle the default in the save() method.

def save(self, **kwargs):
    if not self.id:
        self.id = get_entity_id()
    super(Entity, self).save(**kwargs)

Or, better yet, just remove the "id = models.BigIntegerField" line 
completely and let django give you a models.AutoField which should properly 
auto-increment.

Collin

On Monday, December 15, 2014 7:45:47 AM UTC-5, Gerald Klein wrote:
>
> if I remove the parens, when I submit to create the new entity is throws a 
> validation error that does not specify the field that is wrong, "Please 
> correct the error below."
>
> --jerry
>
> On Mon, Dec 15, 2014 at 6:20 AM, Daniel Roseman <dan...@roseman.org.uk 
> <javascript:>> wrote:
>>
>> 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 django-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> 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
>>  
>> <https://groups.google.com/d/msgid/django-users/312afeac-a3cf-479b-a544-7f6690732257%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
>
> Gerald Klein DBA
>
> cont...@geraldklein.com <javascript:>
>
> www.geraldklein.com 
> <http://t.senalcinco.com/e1t/c/5/f18dQhb0S7lC8dDMPbW2n0x6l2B9nMJW7t5XZs1p1kmsW3N1NWP1p8b8gW3LPXXH56dyQSf6HGzv402?t=http%3A%2F%2Fgeraldklein.com%2F&si=5404167384858624&pi=12af2f4f-d854-4f2b-d29e-aa6ab7ce9884>
>
> geraldklein.wordpress.com 
> <http://t.senalcinco.com/e1t/c/5/f18dQhb0S7lC8dDMPbW2n0x6l2B9nMJW7t5XZs1p1kmsW3N1NWP1p8b8gW3LPXXH56dyQSf6HGzv402?t=http%3A%2F%2Fgeraldklein.wordpress.com%2F&si=5404167384858624&pi=12af2f4f-d854-4f2b-d29e-aa6ab7ce9884>
>
> j...@zognet.com <javascript:>
>
> 708-599-0352 
> <http://t.senalcinco.com/e1t/c/5/f18dQhb0S7lC8dDMPbW2n0x6l2B9nMJW7t5XZs1p1kmsW3N1NWP1p8b8gW3LPXXH56dyQSf6HGzv402?t=&si=5404167384858624&pi=12af2f4f-d854-4f2b-d29e-aa6ab7ce9884>
>
>
> Arch, Gentoo I3, Ranger & Vim the coding triple threat.
>
> Linux registered user #548580 
>
> Brought to you by the Amish Mafia
>
>  

-- 
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+unsubscr...@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/5a204c8e-68f7-49f3-9326-973f89442915%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to