Hi,
I have a model property in the django framework that returns a list of dict
Is there any way to type it more easily than using a resolver?
Currently my code looks like this:
My django model:
class MySite:
@property
def player_data(self):
data = [
{
"src": signed_movie_url(self.project_path, "video-1080p.mp4"),
"size": 1080,
"type": "video/mp4",
},
{
"src": signed_movie_url(self.project_path, "video-720p.mp4"),
"size": 720,
"type": "video/mp4",
},
{
"src": signed_movie_url(self.project_path, "video-540p.mp4"),
"size": 540,
"type": "video/mp4",
},
]
return data
My types:
@strawberry.type
class SiteType:
@strawberry.type()
class PlayerSiteDataType:
src: str
size: int
type: str
@staticmethod
def player_data(root):
return [SiteType.PlayerSiteDataType(**i) for i in root.player_data]
name: str
player_data: List[PlayerSiteDataType] = strawberry.field(resolver=player_data)
Thanks.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too