On 3/13/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
On 3/12/06, Glenn Tenney <[EMAIL PROTECTED]> wrote:
The auto-incrementing happens at the database level, after the INSERT
statement is done. This happens at the database level on purpose --
Django doesn't do the auto-incrementing for you, because the database
does a good enough job. :)

For your particular problem, I'd suggest one of these techniques:

* Rely on the database-level auto-incrementing and use _post_save() to
compute your value. However, be aware that this technique would hit
the database twice for every INSERT save().

Be vary careful, this will probably break the first day you start getting traffic. Without locking/transaction support it is bound to fail.

* Bypass database-level auto-incrementing and handle that on your own,
in _pre_save(). You'd have to manually calculate the next available ID
in _pre_save(). Then compute your value based on that.

The reason we do database level auto incrementing is because this is the only reliable way [within django] to do it. The only other way I would do it is create an auxiliary table with only an auto incrementing values, and use it for "bypassing database-level auto-incrementing". Or run a seperate service that gives me autoincrementing number everytime you access them.

* Write a trigger at the database level that automatically calculates
the computed field whenever a record changes in the table. This would
be entirely out of Django's control, handled purely at the database
level.

This is possibly the only solution, but is an overkill to your problem of just maintaining an auto incrementing integer. I have not checked, but using null=True, passing None, and modifying the table to add autoincrement would be way to go [if it works].

--
Amit Upadhyay
Blog: http://www.rootshell.be/~upadhyay
+91-9867-359-701
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to