Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Adding support for default values
Browse files Browse the repository at this point in the history
Fixes #30
  • Loading branch information
sdispater committed Dec 22, 2015
1 parent 12a1219 commit 5ee2411
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion orator/orm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class Model(object):

_register = ModelRegister()

__attributes__ = {}

many_methods = ['belongs_to_many', 'morph_to_many', 'morphed_by_many']

CREATED_AT = 'created_at'
Expand All @@ -120,7 +122,9 @@ def __init__(self, _attributes=None, **attributes):

self._exists = False
self._original = {}
self._attributes = {}

# Setting default attributes' values
self._attributes = dict((k, v) for k, v in self.__attributes__.items())
self._relations = {}

self.sync_original()
Expand Down
12 changes: 12 additions & 0 deletions tests/orm/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,11 @@ def test_get_foreign_key(self):

self.assertEqual('stub_id', model.get_foreign_key())

def test_default_values(self):
model = OrmModelDefaultAttributes()

self.assertEqual('bar', model.foo)


class OrmModelStub(Model):

Expand Down Expand Up @@ -1089,3 +1094,10 @@ class OrmModelCreatedAt(Model):
class OrmModelUpdatedAt(Model):

__timestamps__ = ['updated_at']


class OrmModelDefaultAttributes(Model):

__attributes__ = {
'foo': 'bar'
}

0 comments on commit 5ee2411

Please sign in to comment.