简体   繁体   English

在Django中列出所有用户

[英]Making a list off all users in Django

I am trying to create a list of all the users on my Django setup in order to list who is working on a device, currently it pulls the usernames. 我正在尝试在Django设置上创建所有用户的列表,以列出正在使用设备的人员,当前它会提取用户名。

REPAIRED_BY = (
    ('BLANK', 'Not Assigned'),
    ('USER1', User.objects.all()),
)

but it does not allow me to list them in a string format (ie Joe Smith). 但是它不允许我以字符串格式列出它们(即Joe Smith)。 I am able to get the first and last name using value_list but it appears as a tuple. 我可以使用value_list获得名字和姓氏,但它显示为元组。 ('Joe','Smith') ( '乔', '史密斯')

repaired_by = models.CharField(max_length=100, choices=REPAIRED_BY, default='BLANK')

It needs to be able to switch users to different devices. 它需要能够将用户切换到不同的设备。 User 1 is working on computers 1 & 2 while user 2 is working on computer 3 用户1在计算机1和2上工作,而用户2在计算机3上工作

Please let me know if you need more information. 如果您需要更多信息,请告诉我。

It seems that you would want to use a ForeignKey field, to bind a User to a Device. 似乎您想使用ForeignKey字段将用户绑定到设备。

https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.ForeignKey https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.ForeignKey

repaired_by = models.ForeignKey(User, null=True)

in order to list [...] does not allow me to list them in a string format (ie Joe Smith). 为了列出而不允许我以字符串格式列出它们(即乔·史密斯)。 I am able to get the first and last name using value_list but it appears as a tuple. 我可以使用value_list获得名字和姓氏,但它显示为元组。 ('Joe','Smith') ( '乔', '史密斯')

I'm not sure I get your issue right, but getting a convenient name display from a tuple of name parts is trivial: 我不确定是否能解决您的问题,但是从名称部分的元组中获得方便的名称显示很简单:

t = ('Joe','Smith') 
print(" ".join(t))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM