def model_pk_lock(func):
 def decorator(self, *args, **kwargs):
  from taiga.base.utils.db import get_typename_for_model_class
  pk = self.kwargs.get(self.pk_url_kwarg, None)
  tn = get_typename_for_model_class(self.get_queryset().model)
  key = '{0}:{1}'.format(tn, pk)
  with advisory_lock(key):
   return func(self, *args, **kwargs)
 return decorator

def model_pk_lock ( func ) : def decorator ( self , * args , ** kwargs ) : from taiga . base . utils . db import get_typename_for_model_class pk = self . kwargs . get ( self . pk_url_kwarg , None ) tn = get_typename_for_model_class ( self . get_queryset ( ) . model ) key = '{0}:{1}' . format ( tn , pk ) with advisory_lock ( key ) : return func ( self , * args , ** kwargs ) return decorator
this decorator is designed to be used in modelviewsets methods to lock them based on the model and the id of the selected object .