比较不同模型的两个字段,而无需在django中使用外键

发布于 2025-01-21 16:33:27 字数 975 浏览 1 评论 0原文

这是关于CRM软件的。

我有两个模型profile_candidateagentprofile_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

殊姿 2025-01-28 16:33:27

如果reference_mobile profile> profile_candidate模型的字段与agent.user.user准确。仔细检查模型字段类型是否相同,如果不是,则您可能正在比较Reference_mobile中的子场,例如用户名或其他类型。

If the Reference_Mobile field of the profile_candidate model is not the same object type as Agent.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 within Reference_Mobile, like a username or other type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文