1 year ago
#288859
hn_tired
Cannot resolve keyword annotated field django
this is my model
class ExchangeReportTime(models.Model):
creator = models.ForeignKey('accounts.Account', on_delete=models.CASCADE, null=True, verbose_name=_('Creator'))
create_time = models.DateTimeField(default=timezone.now)
exchange = models.ForeignKey(BorseExchange, on_delete=models.SET_NULL, null=True,
related_name='report_times')
actual_fiscal_month = models.CharField(max_length=255, null=True, blank=True)
fiscal_month = models.CharField(max_length=5, null=True, blank=True)
fiscal_year = models.CharField(max_length=255, null=True, blank=True)
is_fiscal_year_changed = models.BooleanField(null=True, blank=True)
period_ending_date = models.CharField(max_length=15, null=True, blank=True)
statement_key = models.IntegerField(null=True, blank=True)
statement_type = models.CharField(max_length=50, null=True, blank=True)
...
fiscal_month and fiscal_year are string so i change types and query as below
exchange = BorseExchange.objects.get(tse_code=exchange_number)
last_12_season = exchange.report_times.filter(
statement_type='InterimIncomeStatement',
period_type='seasonally'
).annotate(
fiscal_month_number=Cast('fiscal_month',IntegerField()),
fiscal_year_number=Cast('fiscal_year',IntegerField()),
).order_by(
'-fiscal_year_number', '-fiscal_month_number'
).distinct(
'fiscal_month_number', 'fiscal_year_number'
)[:records_count]
print(last_12_season.values_list('id'))
but i give error:
django.core.exceptions.FieldError: Cannot resolve keyword 'fiscal_month_number' into field. Choices are: actual_fiscal_month, attachment_url, auditing, company_key, create_time, creator, creator_id, currency, exchange, exchange_id, fiscal_month, fiscal_year, html_url, id, is_empty, is_fiscal_year_changed, period_ending_date, period_type, publish_date, publish_time, report_items, scenario, statement_key, statement_type
where is the problem?
python3.6 and django 2.2.*
django
annotate
0 Answers
Your Answer