Django:长对象属性错误
这是我对“长”对象的第一次介绍,我在 Django 文档中没有找到太多有关查询集和长对象的信息。长的物体。我正在尝试将两个不同的查询加入到一个列表中,我可以向每个用户发送电子邮件。
有两个问题 - 这是加入这些查询的正确方法吗?如果是这样,如何访问 profile.user.email
属性而不遇到此长对象错误?
email_list = []
for user in request.user.get_profile().followers.all():
email_list.append(user)
for profile in Profile.objects.filter(city=request.user.get_profile().city.id):
if not profile.user.id in email_list:
print type(profile.user.id)
email_list.append(profile.user.id)
错误:
AttributeError: 'long' object has no attribute 'email'
This is my first introduction to 'Long' Objects, and I haven't found much in the Django docs on Querysets & long objects. I am trying to join two different queries into a list which I can email each user.
Two questions - is this the proper way to join these queries? If so, how do I access the profile.user.email
attribute without hitting this long object error?
email_list = []
for user in request.user.get_profile().followers.all():
email_list.append(user)
for profile in Profile.objects.filter(city=request.user.get_profile().city.id):
if not profile.user.id in email_list:
print type(profile.user.id)
email_list.append(profile.user.id)
Error:
AttributeError: 'long' object has no attribute 'email'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要向列表中添加“长”对象(它们只是数字)而不是实际的 User 实例:
它应该是:
You are adding to the list 'long' objects (they are just numbers) instead of actual User instances:
it should be: