clearer sql parsing and dumping

This commit is contained in:
Nick Sweeting 2019-04-17 03:50:41 -04:00
parent cdb70c73df
commit 35aa8c8902
2 changed files with 5 additions and 8 deletions

View file

@ -18,15 +18,15 @@ class Page(models.Model):
updated = models.DateTimeField(null=True, default=None)
# bookmarked = models.DateTimeField()
sql_args = ('url', 'timestamp', 'title', 'tags', 'updated')
keys = ('url', 'timestamp', 'title', 'tags', 'updated')
@classmethod
def from_json(cls, info: dict):
info = {k: v for k, v in info.items() if k in cls.sql_args}
info = {k: v for k, v in info.items() if k in cls.keys}
return cls(**info)
def as_json(self, *args) -> dict:
args = args or self.sql_args
args = args or self.keys
return {
key: getattr(self, key)
for key in args