문제

I'm working in the admin interface, and I'm trying to create a InlineModelAdmin subclass that given a model will just give me certain values from related values (say, date and value fields) and use them in a subclassed template to build a graph.

Problem is: I don't know what to subclass in the inline!. The inline_admin_formset seems to have the form already cooked and I can't access the date. get_form I can't get to send the data I want to the template. I tried change_view to put the data as extra_context, but it's only called for the parent class. And so on.

Can anyone orient me as to where would be the best place to work?.

I know this would be a lot easier in a custom view, but the high command is adamant that this has to be done in the admin interface.

Thank you!

도움이 되었습니까?

해결책

Looks like I managed to access the raw data from the inline objects using the following code in the template:

<script>
var data = google.visualization.arrayToDataTable([
        ["Date", "Value"],
        {% for form in inline_admin_formset %}
            ["{{form.original.date}}", {{form.original.value}}],
        {% endfor %}
    ]);
</script>

So it looks like now I only need to parameterize what fields the graph is going to plot from the inline, or from the object (date and value in this case). Perhaps add a graph_fields() method to both.

In any case, thanks to whoever gave this a thought.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top