Я новичок в разработке, и я в тупике.Я пытаюсь создать систему грантов для Python3 и Django
У меня есть модели:
class Grant(models.Model):
id = models.AutoField(primary_key=True)
program = models.ForeignKey('Program', on_delete=models.SET_NULL, null=True)
title = models.CharField(max_length=200, help_text="Enter name of the grant")
budget = models.DecimalField(max_digits=12, decimal_places=2,default=Decimal('0.00'),verbose_name="Total budget")
grantee = models.ForeignKey('Grantee', on_delete=models.SET_NULL, null=True)
description = models.TextField(max_length=1000)
owner = models.ForeignKey(settings.AUTH_USER_MODEL,null=True, blank=True, on_delete=models.SET_NULL)
class Report(models.Model):
title = models.CharField(max_length=100)
grant_name = models.ForeignKey('Grant', on_delete=models.SET_NULL, null=True)
CAT_LIST = (
('s', 'Salary'),
('e', 'Event'),
('t', 'Transportation'),
('p', 'Printing'),
('eq', 'Equipment'),
('of', 'Office'),
('o', 'Other')
)
categories = models.CharField(max_length=2, choices=CAT_LIST, blank=True)
spent = models.DecimalField(max_digits=12, decimal_places=2,default=Decimal('0.00'))
repbudget = models.DecimalField(max_digits=12, decimal_places=2,default=Decimal('0.00'),verbose_name="Budget")
comment = models.TextField(max_length=300, null=True)
# Below the mandatory fields for generic relation
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey()
class Installment(models.Model):
id = models.AutoField(primary_key=True)
grant_name = models.ForeignKey('Grant', on_delete=models.SET_NULL, null=True)
amount = models.DecimalField(max_digits=12, decimal_places=2,default=Decimal('0.00'))
date = models.DateField(default=datetime.date.today)
date_report = models.DateField(default=datetime.date.today)
Теперь мне нужно создать модель для Отчета об оплате в рассрочку, и она должна включать Рассрочки и Отчетыкатегории для одного гранта.Примерно так:
class InstallmentReport(models.Model):
id = models.AutoField(primary_key=True)
title = models.ForeignKey('Report', on_delete=models.CASCADE)
spent = models.DecimalField(max_digits=12, decimal_places=2,default=Decimal('0.00'))
installment = models.ForeignKey('Installment', on_delete=models.CASCADE)
Когда я создаю этот отчет, я могу соединиться с Installment
, но не могу представить, как отфильтровать заголовок отчета для того же гранта.Не могли бы вы дать какой-нибудь совет или, может быть, какой-нибудь пример?
PS Я прошу прощения за мои ошибки на английском языке и, возможно, при разработке кода