Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我在 django 模型中有一个 Datefield,如何从模型对象中获取所有可能的月份值?所以如果我有 date = 22.01.2013 的 object1 和 date = 23.05.2013 的 object2,我需要获取月份列表 [01, 05] 或 [1, 5]
你可以这样做:
months = [i.month for i in MyModel.objects.values_list('date', flat=True)]
嘿,我认为日期功能是您正在寻找的:
尝试:
month_list = Model.objects.dates('DateField', 'month')