Image of Database Sources_verticlas table
此表显示映射。 该表不应该允许重复数据,就像它在以下方面所做的那样: Paytm:电子商务,酒店,旅游 Paytm:电子商务,旅行
它不应该提供在Paytm下映射预映射元素的选项,或者它应该将Hotel合并到以前存在的记录中。
答案 0 :(得分:0)
据我所知你需要这样的东西。这可能不是一个好的解决方案,但它可以满足您的需求:
Verticals Sources Sources_Verticals
--------- ------- -----------------
Paymt Ecommerce Paymt - Ecommerce, Hotel
Hotel Paymt - Travel
Travel
# query Paymt to get id
vertical = Verticals.objects.get(vertical_name='Paymt')
# use Paymt id to get all record in Sources_Verticals table which related with Paymt
source_ver = Sources_Verticals.objects.get(vertical_id=vertical.id)
# all sources
sources = Sources.objects.all()
# iterate over sources to
for source in sources:
# check which source not in the list
if source.id not in source_ver:
# save this source with Paymt
s = Sources_Verticals(vertical_id=vertical.id, source_id=source.id)
s.save()