Reputation: 23
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.
REPAIRED_BY = (
('BLANK', 'Not Assigned'),
('USER1', User.objects.all()),
)
but it does not allow me to list them in a string format (i.e. Joe Smith). I am able to get the first and last name using value_list but it appears as a tuple. ('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
Please let me know if you need more information.
Upvotes: 2
Views: 218
Reputation: 1189
It seems that you would want to use a ForeignKey field, to bind a User to a Device.
https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.ForeignKey
repaired_by = models.ForeignKey(User, null=True)
Upvotes: 2
Reputation: 1736
in order to list [...] does not allow me to list them in a string format (i.e. Joe Smith). I am able to get the first and last name using value_list but it appears as a tuple. ('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))
Upvotes: -1