我有一个代表日历事件的Django模型:
class Event(models.Model):
title = models.CharField(max_length=120)
date = models.DateField(default=default_event_date)
category = models.ForeignKey(Category)
users = models.ManyToManyField(User, related_name='events',
limit_choices_to={'is_staff': True})
...
如何从该模型中获取查询集并组织数据,以便可以在模板中显示它:
Date1 Date2 Date3 Date4 ...
User1 CatA (Title1) CatC (Title4) CatB (Title7) -
User2 CatD (Title2) CatB (Title5 - CatD (Title9)
User3 CatC (Title3) CatC (Title4) CatC (Title8) CatC (Title10)
User4 - - - -
User5 - CatA (Title6) - CatD (Title9)
...
DateN是date
字段,UserN是users
字段,CatX是category
字段,TitleN是title
。