Django 从一个模型中获取其他模型的pk models.py
如何从销售模型/对象获取客户id?Django 从一个模型中获取其他模型的pk models.py,django,django-rest-framework,django-views,Django,Django Rest Framework,Django Views,如何从销售模型/对象获取客户id? 类似于Sell.objects.get(pk=…)您可以使用外键概念获取 在这里,您可以使用Sellmodel的客户字段获得Customermodel的pk,它将是Customer\uu pk 类似地,customer\u name您可以通过customer\u customer\u name和address使用customer\u address和bill\u no获得 注意:记住它是FieldName IngrentModel\uu othermodelf
类似于
Sell.objects.get(pk=…)
您可以使用外键
概念获取
在这里,您可以使用Sellmodel的客户字段获得Customermodel的pk
,它将是Customer\uu pk
类似地,customer\u name
您可以通过customer\u customer\u name
和address
使用customer\u address
和bill\u no
获得
注意:记住它是FieldName IngrentModel\uu othermodelfieldname,它是双下划线
Sell.objects.get(pk=customer__pk)
您可以使用外键
概念获取
在这里,您可以使用Sellmodel的客户字段获得Customermodel的pk
,它将是Customer\uu pk
类似地,customer\u name
您可以通过customer\u customer\u name
和address
使用customer\u address
和bill\u no
获得
注意:记住它是FieldName IngrentModel\uu othermodelfieldname,它是双下划线
Sell.objects.get(pk=customer__pk)
您的意思是要获取给定Sell
对象的关联客户id吗?如果是,那么因为您在Sell
模型上已经有customer
字段,您可以通过my\u Sell\u object.customer.pk
(其中my\u Sell\u object
是Sell
的一个实例)获取。您的意思是要获取给定Sell
对象的关联客户id吗?如果是,那么因为您在Sell
模型上已经有customer
字段,您可以通过my\u Sell\u object.customer.pk
(其中my\u Sell\u object
是Sell
的一个实例)获取。