zorm /

Filename Size Date modified Message
63 B
502 B
1.8 KB
427 B
3.0 KB
314 B
60 B

Allows for automatic attributes based on table columns.


from autumn.model import Model
class MyModel(Model):

# Create new instance using args based on the order of columns
m = MyModel(1, 'A string')

# Or using kwargs
m = MyModel(field=1, text='A string')

# Saving inserts into the database (assuming it validates [see below])

# Updating attributes
m.field = 123

# Updates database record

# Deleting removes from the database

# Purely saving with an improper value, checked against
# Model.Meta.validations[field_name] will raise Model.ValidationError
m = MyModel(field=0)

# 'ValidationError: Improper value "0" for "field"'

# Retrieval is simple using Model.get
# Returns a Query object that can be sliced

# Returns a MyModel object with an id of 7
m = MyModel.get(7)

# Limits the query results using SQL's LIMIT clause
# Returns a list of MyModel objects
m = MyModel.get()[:5]   # LIMIT 0, 5
m = MyModel.get()[10:15] # LIMIT 10, 5

# We can get all objects by slicing, using list, or iterating
m = MyModel.get()[:]
m = list(MyModel.get())
for m in MyModel.get():
    # do something here...

# We can where our Query
m = MyModel.get(field=1)
m = m.where(another_field=2)

# This is the same as
m = MyModel.get(field=1, another_field=2)

# Set the order by clause
m = MyModel.get(field=1).order_by('field DESC')
# Removing the second argument defaults the order to ASC
msgpack redis-python python-libmemcached