def _create_objects_from_row(self, row): raise_if_exists(Room, id=row['roomid']) location = get_object_or_fail(Location, id=row['locationid']) attributes = dict([attr.split('=', 1) for attr in row.get('attr', [])]) room = Room(id=row['roomid'], location=location, description=row['descr'], data=attributes) try: room.position = PointField().to_python(row['position']) except (ValidationError, ValueError): raise InvalidValue(row['position']) return [room]
def get_db_prep_value(self): expected_db_string = "(7.1,5.12)" point = (Decimal("7.1"), Decimal("5.12")) field = PointField() db_string = field.get_db_prep_value(point) self.assertEquals(expected_db_string, db_string)
def test_to_python_from_string(self): expected_point = (Decimal("1.2"), Decimal("3.4")) point_string = "(1.2, 3.4)" field = PointField() point = field.to_python(point_string) self.assertEquals(expected_point, point)