浏览代码

Fix model json conversion (#108)

* Add all fields when converting model to json
* Fix switched image/description in page meta
Nikhil Rao 2 年之前
父节点
当前提交
933c3678d4
共有 3 个文件被更改,包括 15 次插入2 次删除
  1. 3 1
      pynecone/app.py
  2. 11 0
      pynecone/model.py
  3. 1 1
      pynecone/var.py

+ 3 - 1
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)

+ 11 - 0
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."""

+ 1 - 1
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(