Skip to content

Commit

Permalink
Merge pull request #10 from Wiston999/development
Browse files Browse the repository at this point in the history
Fixed bug with required fields, updated example.py
  • Loading branch information
Wiston999 committed Mar 27, 2016
2 parents 8d2526c + 193be84 commit 3ed37b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class User(NestedField):
url = TextField()
user_type = TextField(name = 'type')
site_admin = BooleanField()
name = TextField(required = False)
email = TextField(required = False)
full_name = TextField(name = 'name', required = False)


class Repo(NestedField):
Expand All @@ -37,7 +38,8 @@ class RepoList(ListField):
my_user = User(response.json())
print my_user.login.value, "'s stats:"
print "id:", my_user.id.value
print "full_name:", my_user.name.value
print "email:", my_user.email.value
print "full_name:", my_user.full_name.value
print "login:", my_user.login.value
print "url:", my_user.url.value
print "type:", my_user.user_type.value
Expand Down
6 changes: 3 additions & 3 deletions json2py/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ def __init__(self, value = None, name = None, required = True):
for key, field in lookUpKeys.items():
if key not in data and field.required:
raise LookupError('%s was not found on data dict' % key)
elif not field.required:
field = field.__class__(None)
else:
elif key in data:
field = field.__class__(data[key])
else:
field = field.__class__(None)
self.value[reverseLookUp[key]] = field
# setattr(self, reverseLookUp[key], field)

Expand Down

0 comments on commit 3ed37b5

Please sign in to comment.