class City(Model): id = Property(str, name='geonameid', primary_key=True) name = Property(str) country = Property(str) subcountry = Property(str)
class Artist(Model): class Options: slots = True id = Property(int, primary_key=True) title = Property(str)
class User(Model): class Options: slots = True id = Property(int, primary_key=True) username = Property(str) password = Property(str)
class Album(Model): class Options: slots = True id = Property(int, primary_key=True) artist = Property(Artist) title = Property(str)
class User(Model): id = Property(int, primary_key=True) username = Property(str) password = Property(str) created_at = Property(datetime, default=lambda: datetime.now()) updated_at = Property(datetime, default=lambda: datetime.now())
def __bind_property_relation(cls, properties, key, prop): # Bind `prop` (to ensure metadata is available) prop.bind(cls, key + '_id') # Create identifier property p_id = Property(prop.relation.value_type) p_id.bind(cls, key + '_id') # Create resolve property p_resolve = RelationProperty(p_id, prop.value_type) p_resolve.bind(cls, key) # Store resolve property on model setattr(cls, key, p_resolve) # Store resolve property on model `Properties` setattr(properties, key, p_resolve) properties.__all__[key] = p_resolve # Store identifier property on model `Properties` setattr(properties, key + '_id', p_id) properties.__all__[key + '_id'] = p_id
class Artist(Model): id = Property(int, primary_key=True) title = Property(str)
class Album(Model): id = Property(int, primary_key=True) artist = Property(Artist) title = Property(str)
class Track(Model): id = Property(int, primary_key=True) artist = Property(Artist) album = Property(Album) title = Property(str)