比较不同模型的两个字段,而无需在django中使用外键
这是关于CRM软件的。
我有两个模型profile_candidate
和agent
, profile_candidate
包含大约20个字段,Reference_mobile
是其中之一。 代理
是包含所有用用户使用字段名称用户的用户的名称的模型。
我需要做的是...
我需要比较每个reference_mobile
profile> profile> profile> profile_candidate 与代理模型中可用的所有用户,我需要检索对象profile_candidate(Model)
的reference_mobile
与代理模型中的任何用户都不匹配。
注意:不使用外键Reference_mobile
来自代理模型的字段,因为在填写profile> profile_candidate
的形式时,我无法将所有用户显示给候选人。
这是我过去两天一直面临的问题,我也是Django和Python的初学者。
我还尝试了许多其他不同的方式,但找不到适当的输出。
我希望我清楚地解释了这个问题。 请任何人帮助我实现这一目标。.
我的views.py
:
def lead_unassigned(request):
team_values = profile_candidate.objects.exclude(Reference_Mobile = Agent.user)
return render(request, 'leads/lead_list_unassigned.html',
{'team_values':team_values})
事先感谢您,
Dinesh Babu
This is regarding CRM software.
I have two models profile_candidate
and Agent
,profile_candidate
contains some 20 fields and Reference_Mobile
is one of them.Agent
is the model which contains the names of all the users who work as agents with the field name user.
Here what I need to do is...
I need to compare the field Reference_Mobile
of each profile_candidate
with all the users available in Agent model, and I need to retrieve the objects of profile_candidate(model)
where the Reference_Mobile
is not matching with any of the users in the Agent Model.
Note: Without using foreign key for Reference_Mobile
field from the Agent model, because I cannot display all the users to the candidates while filling the form of profile_candidate
.
This is the problem I have been facing for the last two days, I am beginner of Django and python too.
I also tried many other different ways but I could not find the proper output.
I hope I explained clearly the problem.
Please anyone help me out in achieving this..
my views.py
:
def lead_unassigned(request):
team_values = profile_candidate.objects.exclude(Reference_Mobile = Agent.user)
return render(request, 'leads/lead_list_unassigned.html',
{'team_values':team_values})
Thanking you in Advance,
Dinesh Babu
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
reference_mobile
profile> profile_candidate
模型的字段与agent.user.user
准确。仔细检查模型字段类型是否相同,如果不是,则您可能正在比较Reference_mobile
中的子场,例如用户名或其他类型。If the
Reference_Mobile
field of theprofile_candidate
model is not the same object type asAgent.user
then the exclude will not be able to compare the two accurately. Double check that the model field types are the same, if they are not then you may be comparing a sub-field withinReference_Mobile
, like a username or other type.