11import json
2- from typing import Any , Dict , List , Optional
2+ from typing import Any , Dict , List , Optional , Type
33
44from django .core .exceptions import ImproperlyConfigured
5+ from django .db .models import Model
56from django .template .loader import render_to_string
67
78import asset_definitions
@@ -18,7 +19,9 @@ class ModelDataMixin:
1819
1920 class Meta :
2021 fields : Optional [List [str ]] = None
21- model : Optional [str ] = None
22+ model : Optional [Model ] = None
23+
24+ _meta : Type ["ModelDataMixin.Meta" ]
2225
2326 def get_fields (self ) -> Optional [List [str ]]:
2427 # TODO: for some reason mypy complains about this one line
@@ -56,9 +59,13 @@ class PlotlyChartSerializerMixin:
5659 template_name : str = "dashboards/components/chart/plotly.html"
5760 meta_layout_attrs = ["title" , "width" , "height" ]
5861 layout : Optional [Dict [str , Any ]] = None
59- displayModeBar : Optional [bool ] = True
60- staticPlot : Optional [bool ] = False
61- responsive : Optional [bool ] = True
62+
63+ _meta : Type [Any ]
64+
65+ class Meta :
66+ displayModeBar : Optional [bool ] = True
67+ staticPlot : Optional [bool ] = False
68+ responsive : Optional [bool ] = True
6269
6370 def empty_chart (self ) -> str :
6471 return json .dumps (
@@ -123,14 +130,16 @@ def render(cls, template_id, **kwargs) -> str:
123130 context = {
124131 "template_id" : template_id ,
125132 "value" : value ,
126- "displayModeBar" : self .displayModeBar ,
127- "staticPlot" : self .staticPlot ,
128- "responsive" : self .responsive ,
133+ "displayModeBar" : self ._meta . displayModeBar ,
134+ "staticPlot" : self ._meta . staticPlot ,
135+ "responsive" : self ._meta . responsive ,
129136 }
130137 return render_to_string (cls .template_name , context )
131138
132139
133140class BaseChartSerializer (ClassWithMeta , asset_definitions .MediaDefiningClass ):
141+ _meta : Type [Any ]
142+
134143 class Meta :
135144 title : Optional [str ] = None
136145 width : Optional [int ] = None
@@ -165,6 +174,9 @@ class PlotlyChartSerializer(PlotlyChartSerializerMixin, BaseChartSerializer):
165174 Serializer to convert data into a plotly js format
166175 """
167176
177+ class Meta (PlotlyChartSerializerMixin .Meta , BaseChartSerializer .Meta ):
178+ pass
179+
168180 class Media :
169181 js = ("dashboards/vendor/js/plotly.min.js" ,)
170182
@@ -174,3 +186,8 @@ class ChartSerializer(ModelDataMixin, PlotlyChartSerializer):
174186 Default chart serializer to read data from a django model
175187 and serialize it to something plotly js can render
176188 """
189+
190+ class Meta (ModelDataMixin .Meta , PlotlyChartSerializer .Meta ):
191+ pass
192+
193+ _meta : Type ["ChartSerializer.Meta" ]
0 commit comments