views:

81

answers:

0

Hello,

I have to show entries by date in a django app and i'm a bit blocked : Here's an example of my models:

class Event(models.Model):  
    name = models.CharField(max_length=100)  
    theme = models.ForeignKey(Theme)
    ...

class Date(models.Model):  
    event = models.ForeignKey(Event)  
    start = models.DateField()  
    end = models.DateField()

    class Meta:
        ordering = ['start', 'end']
        unique_together = ['event', 'start']

I got a view that take all the events in the database : Event.objects.all()

and then in a template i show the list of events with their theme and other stuffs like the date start. I would like to show in the list the first "future" date, that's easy with a custom method on the event model:

def get_first_future_date(self):
    today = datetime.datetime.now()
    dates = self.date_set.filter(end__gte=today)
    if dates:
        return dates[0]

That method the first future date or the oldest date that isn't finished.
Here's the problem : I would like to show that field in my template and be able to sort it with django-sorting.

Django-sorting uses {% anchor arg %} to do it but i don't know how to manage that field in it... How would you do that???

Thanks by advance for any answer.