chartit / django-chartit

A Django app to plot charts and pivot charts directly from the models. Uses HighCharts and jQuery JavaScript libraries to render the charts on the webpage.
http://django-chartit.mrsenko.com/
Other
492 stars 166 forks source link

Checks only the model fields/fails with extra fields in the query set #8

Closed atodorov closed 8 years ago

atodorov commented 11 years ago

Hi, I got this error:

chartit/validation.py" in _validate_field_lookup_term
  32.                          % (terms[0], ', '.join(model_fields)))

Exception Type: APIInputError at /..../
Exception Value: Field 'added' does not exist. Valid lookups are comment, id, key, metric, milestone, when_added.

The relevant code is:

metricsdata = DataPool(
        series= [{'options': { 'source': InternalTimedMetrics.objects.extra(select={'added': "DATE_FORMAT(when_added,'%Y-%m-%d')"}).filter(key=METRIC_APPS_ACTIVE) },
                'terms': [ 'metric', 'added']
                }
            ]
        )

#Step 2: Create the Chart object
cht = Chart(
        datasource = metricsdata,
        series_options =
          [{'options':{
              'type': 'line',
              'stacking': False},
            'terms':{
              'added': ['metric']
              }}]
        )

I'm trying to workaround the fact that datetime is not supported for X axis by converting the values to string right in the DB layer but your sanity checks got me.