How to make relationship in django models in such scenario

23 views
Skip to first unread message

Dhruvil Shah

unread,
Dec 31, 2020, 5:14:15 AM12/31/20
to django...@googlegroups.com

models.py So,here i want to make Invoicemgmt model in which i can have multiple entries for Invoice table having customer,project and Invoice_amount.

Basically,requirement is that whenever i see 'view_Invoice' of some id,first i will see all data of that specific id on that page and then i want to have small table below for invoice_mgmt,where i can add amount received for that specific id invoice.

*so,i want to know what fields should i add in invoice_mgmt model for relationship "


"models.py"
class Invoice(models.Model):
    company_choice = (
        ('VT_India', 'VT_India'),
        ('VT_USA', 'VT_USA'),
    )
    company = models.CharField(
        max_length=30, blank=True, null=True, choices=company_choice)
    customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
    project = models.ForeignKey(Allproject, on_delete=models.CASCADE)

    invoice_title = models.CharField(max_length=15)

    invoice_id = models.IntegerField(primary_key=True)
    invoice_amount = models.IntegerField()
    invoice_date = models.DateField(
        blank=True, null=True)
    invoice_duedate = models.DateField(
        blank=True, null=True)

    invoice_description = models.TextField()

    def __str__(self):
        return self.invoice_title


class Paymentmethod(models.Model):
    paymentmethod_id = models.IntegerField(primary_key=True)
    paymentmethod_name = models.CharField(max_length=15)

    def __str__(self):
        return self.paymentmethod_name


class Invoicemgmt(models.Model):
    invoicemanagement_id = models.IntegerField(primary_key=True)
    invoice_received = models.IntegerField()
    date = models.DateField(
        blank=True, null=True)
    payment_method = models.ForeignKey(Paymentmethod, on_delete=models.CASCADE)

"So, basically i want to have multiple entries in invoice mgmt table for one specific invoice table id(one specific data)"
Reply all
Reply to author
Forward
0 new messages