From c647bd4b5669d4b4255602e9b222413bee88590d Mon Sep 17 00:00:00 2001 From: pedrospdc Date: Fri, 3 Feb 2017 18:35:04 +0100 Subject: [PATCH] Add support for relational lookups on ObjectsByDateTracker --- trackstats/trackers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/trackstats/trackers.py b/trackstats/trackers.py index 9f06627..6a4c710 100644 --- a/trackstats/trackers.py +++ b/trackstats/trackers.py @@ -5,6 +5,7 @@ from django.db import models from django.db import connections from django.utils import timezone +from functools import reduce from .models import Period, StatisticByDate, StatisticByDateAndObject @@ -20,6 +21,9 @@ def __init__(self, **kwargs): for prop, val in kwargs.items(): setattr(self, prop, val) + def _get_start_date(self, obj, start_date): + return + def get_most_recent_kwargs(self): most_recent_kwargs = { 'metric': self.metric, @@ -37,7 +41,7 @@ def get_start_date(self, qs): if first_instance is None: # No data return - start_date = getattr(first_instance, self.date_field) + start_date = reduce(getattr, self.date_field.split('__'), first_instance) if start_date and isinstance(start_date, datetime): if timezone.is_aware(start_date): start_date = timezone.make_naive(start_date).date()