paid_bills = bill_payment_history.objects.filter(date_paid__year='2023', date_paid__month='03')
as criteria for another query to only show the unpaid bills.
The known_bills model is my control list of known bills that occur frequently.
The
bill_payment_history model is my bill transaction table. It is a running history of transactions for bill payment.
bill_1 paid last month
bill_2 paid last month
bill_3 paid last month
bill_1 paid this month
bill_2 paid this month
bill_3 paid this month
What I am trying to do is use bill_payment_history filtered on date_paid by year and month and query the known_bills table to see what bills have not been paid yet. I keep trying something similar to: results = paid_bills.exclude(short_description__in=known_bills)
but my results either keep coming up with all of the records or none of them. What am I doing wrong?
Here is the model information:
class known_bills(models.Model):
#Full bank transaction
description = models.CharField(max_length=255)
#String value to search the CSV file with.
short_description = models.CharField(max_length=255, unique=True)
#Value I know it as.
friendly_name = models.CharField(max_length=255)
expected_due_date = models.DateField()
expected_cost = models.DecimalField(max_digits=6,decimal_places=2)
class bill_payment_history(models.Model):
description = models.CharField(max_length=255)
short_description = models.ForeignKey(known_bills, on_delete=models.CASCADE)
friendly_name = models.CharField(max_length=255)
date_paid = models.DateField()
cost = models.DecimalField(max_digits=6,decimal_places=2)
class Meta:
unique_together = (
('short_description',
'date_paid'),
)