@tx.atomic
def add_vote(obj, user):
 obj_type = apps.get_model('contenttypes', 'ContentType').objects.get_for_model(obj)
 with advisory_lock('vote-{}-{}'.format(obj_type.id, obj.id)):
  (vote, created) = Vote.objects.get_or_create(content_type=obj_type, object_id=obj.id, user=user)
  if (not created):
   return
  (votes, _) = Votes.objects.get_or_create(content_type=obj_type, object_id=obj.id)
  votes.count = (F('count') + 1)
  votes.save()
  return vote

@ tx . atomic def add_vote ( obj , user ) : obj_type = apps . get_model ( 'contenttypes' , 'ContentType' ) . objects . get_for_model ( obj ) with advisory_lock ( 'vote-{}-{}' . format ( obj_type . id , obj . id ) ) : ( vote , created ) = Vote . objects . get_or_create ( content_type = obj_type , object_id = obj . id , user = user ) if ( not created ) : return ( votes , _ ) = Votes . objects . get_or_create ( content_type = obj_type , object_id = obj . id ) votes . count = ( F ( 'count' ) + 1 ) votes . save ( ) return vote
add a vote to an object .