The kwargs are parameters which are pairs of field names and values. Constructing a Model object is not enough to create a new record. You must call Model.save(). In general, you should use Model.create() or QuerySet.append().
# Creating new team and appending members
new_team = Team.create(name="Houkago Tea Time")
new_team.members.append(first_name="Azusa", last_name="Nakano", part="Gt2", age=16)
new_team.members.append(first_name="Sawako", last_name="Yamanaka", part="Gt1", age=28)
# Retrieving member, updating
azusa = Member.get("first_name=?", ["Azusa"])
sawako = Member.get(2) # Getting with ID
sawako.part = "Vo"
sawako.save() # Reflecting to database
# Deleting
azusa.delete()
sawako.delete()
Return type: | TableMetaInfo instance |
---|
TableMetaInfo is constructed when you access this property first.
Parameters: |
|
---|---|
Return type: | Model instance |
If you set WHERE clause into value with parameters, you must use place holders for security reasons. As this:
member = Member.get("name=?", ["Azusa"])
Or, you can specify primary key value:
member = Member.get(1)
The Model.get() expects the single record. If multiple results are returned, MultipleObjectsReturned is raised.
Parameters: |
|
---|---|
Return type: | QuerySet instance |
This likes Model.get(), but returns QuerySet.