Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

how to make relationship in django model

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 "


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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...