【发布时间】:2022-11-14 08:14:20
【问题描述】:
我想显示总收入等于总价,总价是预约模型中的一个字段 我想要那个特定字段的计数,以便我可以在 HTML 中显示它。
class Appointment(models.Model):
# Invoicing Section
service_name = models.CharField(max_length=120, default='', blank=True, null=True)
total_price = models.CharField(max_length=100,default='', blank=True, null=True)
upfront_payment = models.CharField(max_length=100,default='', blank=True, null=True)
grand_total = models.CharField(max_length=100,default='', blank=True, null=True)
invoice_date = models.DateField(auto_now_add=True, blank=True, null=True)
invoice_type_choice = (
('EVCPLUS', 'EVCPLUS'),
('SH.SO', 'SH.SO'),
('USD', 'USD'),
)
invoice_type = models.CharField(max_length=50, default='', blank=True, null=True, choices=invoice_type_choice)
payment_status = models.CharField(max_length=10, choices=(('Pending', 'Pending'),
('Completed', 'Completed'), ('Canceled', 'Canceled')), default='Pending')
def __str__(self):
return self.patient.patient_name
我试着这样做:
revenue = Appointment.objects.filter(total_price = Appointment.total_price).count()
return render(request, 'index.html', {
'current_user': current_user,
'sayfa': 'dashboard',
'yearly_patients': yearly_patients,
'monthly_appointments': monthly_appointments,
'yearly_patients_graph': yearly_patients_dict,
'monthly_appointments_graph':monthly_appointments_dict,
'donutDataGraph': donutData,
'appointments': appointments,
'doctors': doctors,
'revenue': revenue,
'search_patient_form': form,
'search_patient_form': search_patient_form
})
但它返回 0 这是不正确的。
【问题讨论】:
-
您能否粘贴您的代码而不是提供屏幕截图的链接?此外,很高兴知道您已经搜索和尝试过什么。
-
对不起,我是新来的
-
别担心。你的问题还不清楚。你想达到什么目标?您要检索数据库中所有约会记录的
total_prices的总和吗? -
这正是我想要的!
标签: python django django-models