def update_or_create_property(self, variable, name, value, value_class='string', property_class=None,
                                  timestamp=None, **kwargs):
        """

        :param variable: Variable Object
        :param name: Property Name (DEVICE:PROPERTY_NAME)
        :param value: a value
        :param value_class: type or class of the value
        :param property_class: class of the property
        :param timestamp:
        :return: VariableProperty Object
        """
        if type(variable) == Variable:
            kwargs = {'name': name.upper(), 'variable_id': variable.pk}
        elif type(variable) == int or type(variable) == float:
            kwargs = {'name': name.upper(), 'variable_id': variable}
        else:
            return None

        vp = super(VariablePropertyManager, self).get_queryset().filter(**kwargs).first()
        kwargs['value_class'] = value_class.upper()
        if timestamp is not None:
            kwargs['timestamp'] = timestamp
        if property_class is not None:
            kwargs['property_class'] = property_class
        if value_class.upper() in ['STRING']:
            kwargs['value_string'] = value
        elif value_class.upper() in ['FLOAT', 'FLOAT64', 'DOUBLE', 'FLOAT32', 'SINGLE', 'REAL']:
            kwargs['value_float64'] = value
        elif value_class.upper() in ['INT64', 'UINT32', 'DWORD']:
            kwargs['value_int64'] = value
        elif value_class.upper() in ['WORD', 'UINT', 'UINT16', 'INT32']:
            kwargs['value_int32'] = value
        elif value_class.upper() in ['INT16', 'INT8', 'UINT8']:
            kwargs['value_int16'] = value
        elif value_class.upper() in ['BOOL', 'BOOLEAN']:
            kwargs['value_boolean'] = value
        if vp:
            # update
            for key, value in kwargs.items():
                setattr(vp, key, value)
            vp.save()
        else:
            # create
            vp = VariableProperty(**kwargs)
            vp.save()

        return vp
def update_or_create_property ( self , variable , name , value , value_class = 'string' , property_class = None , timestamp = None , ** kwargs ) : if type ( variable ) == Variable : kwargs = { 'name' : name . upper ( ) , 'variable_id' : variable . pk } elif type ( variable ) == int or type ( variable ) == float : kwargs = { 'name' : name . upper ( ) , 'variable_id' : variable } else : return None vp = super ( VariablePropertyManager , self ) . get_queryset ( ) . filter ( ** kwargs ) . first ( ) kwargs [ 'value_class' ] = value_class . upper ( ) if timestamp is not None : kwargs [ 'timestamp' ] = timestamp if property_class is not None : kwargs [ 'property_class' ] = property_class if value_class . upper ( ) in [ 'STRING' ] : kwargs [ 'value_string' ] = value elif value_class . upper ( ) in [ 'FLOAT' , 'FLOAT64' , 'DOUBLE' , 'FLOAT32' , 'SINGLE' , 'REAL' ] : kwargs [ 'value_float64' ] = value elif value_class . upper ( ) in [ 'INT64' , 'UINT32' , 'DWORD' ] : kwargs [ 'value_int64' ] = value elif value_class . upper ( ) in [ 'WORD' , 'UINT' , 'UINT16' , 'INT32' ] : kwargs [ 'value_int32' ] = value elif value_class . upper ( ) in [ 'INT16' , 'INT8' , 'UINT8' ] : kwargs [ 'value_int16' ] = value elif value_class . upper ( ) in [ 'BOOL' , 'BOOLEAN' ] : kwargs [ 'value_boolean' ] = value if vp : for key , value in kwargs . items ( ) : setattr ( vp , key , value ) vp . save ( ) else : vp = VariableProperty ( ** kwargs ) vp . save ( ) return vp
:param variable: Variable Object
        :param name: Property Name (DEVICE:PROPERTY_NAME)
        :param value: a value
        :param value_class: type or class of the value
        :param property_class: class of the property
        :param timestamp:
        :return: VariableProperty Object