djagngo 获取所有带有条件的 .objects.filter()
我有一个包含许多列的表 Batch
Column Type Comment
id bigint(20) Auto Increment
start_date datetime(6) NULL
acerage double
batch_health int(11) NULL
stage varchar(100) NULL
expected_delivery_date datetime(6) NULL
current_pdd double NULL
historic_pdd double NULL
current_gdd double NULL
historic_gdd double NULL
sub_farmer_id int(10) unsigned NULL
batch_status varchar(100)
commodity_id int(10) unsigned NULL
commodity_variety_id int(10) unsigned NULL
farm_id bigint(20) NULL
created_at datetime(6)
created_by_id int(10) unsigned NULL
updated_at datetime(6)
updated_by_id int(10) unsigned NULL
actual_produce double NULL
actual_yield_per_acre double NULL
expected_produce double NULL
historical_yield_per_acre double NULL
sop_adherence double NULL
end_date datetime(6) NULL
batch_median_health int(10) unsigned NULL
batch_name varchar(200) NULL
commodity_name varchar(200) NULL
pending_tasks int(10) unsigned NULL
pest_attack varchar(500) NULL
当我尝试从该表获取对象时,
Batch.objects.filter(farm_id = farm_id, batch_status='completed')
,就像已经定义了 farm_id 变量 一样 那么我应该该批次的所有数据列 但我没有得到所有的列,我只得到一个批次名称作为输出,
(2706) Papaya | 2021-03-18
(2707) Papaya | 2021-03-18
如何获取 dict 中的所有列? 这样我就可以在batchyield的过滤器中使用它
batch_id Is a foreign key in batchyield which is batch table ID
并获取batchyield的所有数据 经过
Batchyield.objects.filter(batch_id=batch_id)
I Have a table Batch with many columns
Column Type Comment
id bigint(20) Auto Increment
start_date datetime(6) NULL
acerage double
batch_health int(11) NULL
stage varchar(100) NULL
expected_delivery_date datetime(6) NULL
current_pdd double NULL
historic_pdd double NULL
current_gdd double NULL
historic_gdd double NULL
sub_farmer_id int(10) unsigned NULL
batch_status varchar(100)
commodity_id int(10) unsigned NULL
commodity_variety_id int(10) unsigned NULL
farm_id bigint(20) NULL
created_at datetime(6)
created_by_id int(10) unsigned NULL
updated_at datetime(6)
updated_by_id int(10) unsigned NULL
actual_produce double NULL
actual_yield_per_acre double NULL
expected_produce double NULL
historical_yield_per_acre double NULL
sop_adherence double NULL
end_date datetime(6) NULL
batch_median_health int(10) unsigned NULL
batch_name varchar(200) NULL
commodity_name varchar(200) NULL
pending_tasks int(10) unsigned NULL
pest_attack varchar(500) NULL
when I trying to get the object from this table like this
Batch.objects.filter(farm_id = farm_id, batch_status='completed')
farm_id variable is already defined
then I should all the data column for that Batch
But I am not getting ALL all columns I am getting an only batch name as an output
(2706) Papaya | 2021-03-18
(2707) Papaya | 2021-03-18
How can I get all the columns in dict ??
and so that I can use this in the filter of batchyield
batch_id Is a foreign key in batchyield which is batch table ID
and get batchyield all data
by
Batchyield.objects.filter(batch_id=batch_id)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
values_list('id', flat=True)
返回Batch
对象的id
列的查询集Try this:
values_list('id', flat=True)
returns a queryset ofid
columns of theBatch
objects