0

I am a bit stuck... I am building a bookkeeping system as a practice for me to learn django more

I have a model for Bank as below:

class Bank(models.Model):
    bank_name        = models.CharField(max_length=50, blank=True, null=True)
    sales_invoive    = models.ForeignKey("Income", on_delete=models.CASCADE, blank=True, null=True, related_name='sales_invoices')
    payment_date     = models.DateField(blank=True, null=True)

I then have an Income sheet statement like below

class Income(models.Model):
    invoice_number = models.CharField(max_length=20)
    line_item      = models.IntegerField()
    invoice_date   = models.DateField()
    doc_number     = models.ForeignKey(Document, on_delete=models.CASCADE)
    payment_date   = models.ForeignKey(Bank, on_delete=models.CASCADE, related_name='sales_invoices', blank=True, null=True)
    customer_name  = models.ForeignKey(Customer, on_delete=models.CASCADE, blank=True, null=True)
    product_name   = models.ForeignKey(Product, on_delete=models.CASCADE, blank=True, null=True)

My wish is that, when I enter an invoice in the Income sheet I can be able to select the same invoice number from Bank model and when I enter the payment date of that invoice it must update the Income sheet automatically

TIA!!!

4

0 回答 0