I am trying to use a generic date view on a model which has a foreign key to another model where the date is stored. My view class looks like this.
class MileageYearView(YearArchiveView):
queryset = Miles.objects.all()
date_field = 'ride__date'
make_object_list = True
here is what my models look like
class Ride(models.Model):
profile = models.ForeignKey(RideProfile)
leader = models.ForeignKey(Rider)
date = models.DateTimeField('date of ride')
approved = models.BooleanField(default=False)
class Miles(models.Model):
rider = models.ForeignKey(Rider)
ride = models.ForeignKey(Ride)
actual_miles = models.FloatField('actual miles')
And the error I'm encounterint is Miles has no field named 'ride__date'
I'm new to this, and in terms I can understand I am trying to join the two models so I can view all the mile entries for one year.
Only way to achieve this that I've found is to create a @property in class Miles that returns the ride date, as follow:
@property
def ride_date( self ):
return self.ride.date
and use 'ride_date' as the value for date_field in class MileageYearView
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With