Skip to content

Commit

Permalink
chore: Add as_dict function to Individual model
Browse files Browse the repository at this point in the history
  • Loading branch information
reginafcompton committed Jun 7, 2019
1 parent 971a840 commit 9ad653c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mci_database/db/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ def __init__(self,
self.email_address = email_address
self.telephone = telephone

@property
def as_dict(self):
'''
Represent the Individual as a dict that uses empty strings for None values.
'''
dict_repr = {column.name: getattr(self, column.name)
for column in self.__table__.columns}

for k, v in dict_repr.items():
if v is None:
dict_repr[k] = ""
else:
dict_repr[k] = str(v)

return dict_repr

class IndividualDisposition(db.Model):
individual_id = db.Column(db.String(40), db.ForeignKey(
Expand Down

0 comments on commit 9ad653c

Please sign in to comment.