A
Size: a a a
A
DT
DT
A
PB
Course.objects.annotate(
year=models.functions.ExtractYear('created_at'),
month=models.functions.ExtractMonth('created_at'),
).values('year', 'month').distinct('year', 'month').order_by('-year', '-month')
PB
Course.objects.annotate(
year=models.functions.ExtractYear('created_at'),
month=models.functions.ExtractMonth('created_at'),
).values('year', 'month').distinct('year', 'month').order_by('-year', '-month')
<QuerySet [{'year': 2019, 'month': 2}, {'year': 2018, 'month': 12}, {'year': 2018, 'month': 11}, {'year': 2018, 'month': 10}, {'year': 2018, 'month': 8}, {'year': 2018, 'month': 7}, {'year': 2018, 'month': 6}, {'year': 2018, 'month': 5}, {'year': 2018, 'month': 4}]>
PB
PB
Course.objects.annotate(
year=models.functions.ExtractYear('created_at'),
month=models.functions.ExtractMonth('created_at'),
).values('year', 'month').distinct('year', 'month').order_by('-year', '-month')
SELECT DISTINCT ON (year, month) EXTRACT('year' FROM "courses_course"."created_at" AT TIME ZONE 'UTC') AS "year", EXTRACT('month' FROM "courses_course"."created_at" AT TIME ZONE 'UTC') AS "month" FROM "courses_course" ORDER BY "year" DESC, "month" DESC LIMIT 21;
PB
A
PB
A
p
def transfer(apps, schema_editor):
db_alias = schema_editor.connection.alias
BonusTable = apps.get_model('bonus', 'BonusTable')
for i in BonusTable.objects.using(db_alias).all():
if i.nominal == 1:
i.new_nominal = BonusTableNominal.objects.get(pk=1)
class Migration(migrations.Migration):
dependencies = [
('bonus', '0006_auto_20190218_1351'),
]
operation = [
migrations.RunPython(
transfer, reverse_code=migrations.RunPython.noop
)
]
p
DT
Post.objects.values('pub_date__date').annotate(cnt=Count('id')).order_by()
PB
Post.objects.values('pub_date__date').annotate(cnt=Count('id')).order_by()
PB
PB
DT
DT