def update(self, inst, valid_data): x = valid_data.get('x', inst.x) y = valid_data.get('y', inst.y) min_pos, max_pos = Friend.world_size() inst.x = x if x <= max_pos and x >= min_pos else inst.x inst.y = y if y <= max_pos and y >= min_pos else inst.y inst.save() return inst
def update(self, inst, valid_data): x = valid_data.get('x', inst.x) y = valid_data.get('y', inst.y) min_pos, max_pos = Friend.world_size() inst.x = x if x <= max_pos and x >= min_pos else inst.x inst.y = y if y <= max_pos and y >= min_pos else inst.y inst.distance = Friend.objects.filter( me=True ).first().distance_from(inst.x, inst.y) inst.save() return inst
def create(self, valid_data): x = valid_data.get('x') y = valid_data.get('y') if x is None or y is None: return None min_pos, max_pos = Friend.world_size() if x > max_pos or x < min_pos: return None if y > max_pos or y < min_pos: return None me = Friend.objects.filter(me=True).first() distance = me.distance_from(x, y) friend = Friend(x=x, y=y, distance=distance) me.add_friend(friend) return friend