在我的工作中,我经常在我的django模型中有两个表,并且必须连接它们以将此数据作为csv返回.该数据未通过外键连接,但它们具有连接它们的标识符.这是因为我们从两个不同的源导入这些数据,有时缺少对应的数据,因此在创建条目时无法连接它.
我的问题是:如果你想到我经常要返回这些数据,那么在性能方面连接这些数据的最佳方法是什么?
class OrderInvoiceConnector(models.Model):
order_data = models.ForeignKey(Order, related_name="invoice")
invoice_data = models.ForeignKey(Invoice, related_name="order")
Run Code Online (Sandbox Code Playgroud)
class ConnectedData(models.Model):
invoice_id = models.CharField(max_length=255)
country_iso = models.CharField(max_length=255)
invoice_date = models.CharField(max_length=255)
tax = models.FloatField(max_length=255)
price = models.FloatField()
Run Code Online (Sandbox Code Playgroud) python django performance django-models database-performance