Login

Tag "optimistic locking"

Snippet List

Optimistic locking in Admin

Look here: https://bitbucket.org/depaolim/optlock The snippet of Marco De Paoli is much better than this one! :-) ========================================================= If two users save same record, the second one will overwrite first one. Use this snippet to achieve an optimistic locking, so the second user will get an exception. Save the snippet in optlock.py and put it anywhere in your pythonpath. **Do not put _version_opt_lock in readonly_fields** or the snippet will fail! (if you need to hide it, use jquery). The snippet need in request.POST the original value of _version_opt_lock and if you make it a readonly field Django doesn't POST its value. When this [bug](https://code.djangoproject.com/ticket/11277) will be fixed it should be possible to use a hiddeninput widget. models.py example: ... import optlock ... class YourModel(optlock.Model): ... admin.py example: ... import optlock ... class YourModelAdmin(optlock.ModelAdmin): ... That's it :-)

  • admin
  • locking
  • optimistic locking
Read More

1 snippet posted so far.