Hi all,
I wanted to use UUID as primary key in my models. Since Model doesn't
have any add() method, I have to do it like this:
# override Django's save()
def save(self):
import uuid
while not self.id:
# we are adding new row
id = ''.join(str(uuid.uuid4()).split('-'))
try:
MyModel.objects.get(id__exact=id)
except MyModel.DoesNotExit:
self.id = id
return super(MyModel, self).save()
That's TWO queries per addition; not elegant!
Further, to securely handle the incoming POST requests, even without
my save() overriding, validator(s) should issue same TWO requests.
(I'm talking of case where _some_ users are allowed to edit existing
data but others are just allowed to add new data).
Don't you think that the implementation of (current) Model.save()
should be broken into Model.add() and Model.save()? Adding a new entry
and updating an existing one are _different_ operations and the should
not be *automagically* fused together. Even underlying SQL is
separate!
(If I am wrong / not well-informed, kindly show me the right way.)
Regards,
Arvind Singh
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---