From 933c3678d4cc49732686c68997323b005a8aa9ae Mon Sep 17 00:00:00 2001 From: Nikhil Rao Date: Thu, 15 Dec 2022 01:43:24 -0800 Subject: [PATCH] Fix model json conversion (#108) * Add all fields when converting model to json * Fix switched image/description in page meta --- pynecone/app.py | 4 +++- pynecone/model.py | 11 +++++++++++ pynecone/var.py | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pynecone/app.py b/pynecone/app.py index 05928b552..c53349451 100644 --- a/pynecone/app.py +++ b/pynecone/app.py @@ -228,7 +228,9 @@ class App(Base): component = component if isinstance(component, Component) else component(*args) # Add the title to the component. - compiler_utils.add_meta(component, title, description, image) + compiler_utils.add_meta( + component, title=title, image=image, description=description + ) # Format the route. route = utils.format_route(path) diff --git a/pynecone/model.py b/pynecone/model.py index 1171beb31..a53e48432 100644 --- a/pynecone/model.py +++ b/pynecone/model.py @@ -22,6 +22,17 @@ class Model(Base, sqlmodel.SQLModel): # The primary key for the table. id: int = sqlmodel.Field(primary_key=True) + def dict(self, **kwargs): + """Convert the object to a dictionary. + + Args: + kwargs: Ignored but needed for compatibility. + + Returns: + The object as a dictionary. + """ + return {name: getattr(self, name) for name in self.__fields__} + @staticmethod def create_all(): """Create all the tables.""" diff --git a/pynecone/var.py b/pynecone/var.py index 9218804f8..3a535e28e 100644 --- a/pynecone/var.py +++ b/pynecone/var.py @@ -190,7 +190,7 @@ class Var(ABC): and hasattr(self.type_, "__fields__") and name in self.type_.__fields__ ): - type_ = self.type_.__fields__[name].type_ + type_ = self.type_.__fields__[name].outer_type_ if isinstance(type_, ModelField): type_ = type_.type_ return BaseVar(