Thursday, December 31, 2020

How to make relationship in django models in such scenario

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)"

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADsP_iz2TOzNc%2BShAH-SU4xhVu_mxE1xaa1uVHdDy6Vi3mOciw%40mail.gmail.com.

1 comment: