i want to get a list of users and populate it in the select dropdown, but the values don't format properly.
[models.py]
from django.contrib.auth.models import User
class Post(models.Model):
title = models.CharField()
author = models.ForeignKey(User, on_delete= models.CASCADE)
[forms.py]
from django.contrib.auth.models import User
class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = ['title','author']
widgets = {
'author': Select(attrs={'style': 'width: 400px;'}),
}
def __init__(self, *args, **kwargs):
super(PostForm, self).__init__(*args, **kwargs)
self.fields['author'].queryset = User.objects.values_list('first_name')
and this is what Select dropdown for Author shows:
how do i make it shown like below:
-----
Admin
John
