How to use SlickReportField.prepare?
alxvallejo opened this issue · 2 comments
alxvallejo commented
Confused by the documentation here.
I want a column that filters on my model by a certain field value:
SlickReportField.prepare('some_model_field=somevalue')
Where do I put this and how do I tell my Sum
field to use this prepare method?
RamezIssac commented
Hello
Thank you for the question, i'll take another round at the documentation.
class CustomReportField(SlickReprotField):
calculation_method = Sum
def prepare(self, q_filters=None, kwargs_filters=None, **kwargs):
kwargs_filters = kwargs_filers or {}
kwargs_filter['some_model__field'] = 'some Value'
# Or using Q operators, which gives the ability for more complex clauses
q_filters = q_filters or []
q_filters.append(Q(some_model__field='some_value') | Q(some_model__field='other_value') )
return super(SlickReportField, self).prepare(q_filters, kwargs_filters, **kwargs)
Then in views
class MyView(SlickReportView):
columns = ['column1', 'column2', CustomReportField ]
# ...
Let me know how it goes
RamezIssac commented
Hello There 👋
I added this part in the documentation https://django-slick-reporting.readthedocs.io/en/latest/topics/computation_field.html#customizing-the-calculation-flow
Will continue on enhancing it with examples.
Best