def setGlobalProperty(name="", value=0): """ """ try: try: un = GlobalProperty.objects.get(name=name) un.value = value except GlobalProperty.DoesNotExist: un = GlobalProperty(name=name, value=value) un.save() return True except: return False
def incGlobalProperty(name="", incrementBy=1): """Increments value Field by given value, creates Property if DoesNotExist """ try: try: un = GlobalProperty.objects.get(name=name) except GlobalProperty.DoesNotExist: un = GlobalProperty(name=name, value=0) un.value += incrementBy un.save() return True except: return False
def decGlobalProperty(name="", decrementBy=1): """Decrements value Field by given value, creates Property if DoesNotExist """ try: try: un = GlobalProperty.objects.get(name=name) except GlobalProperty.DoesNotExist: un = GlobalProperty(name=name, value=0) if un.value < 1: pass else: un.value -= decrementBy un.save() return True except: return False