Hello, I have a model with 2 tables
Employee
Manager
each employee has a field “manager” thats a foreign key to Manager table
Employee model
class Employee(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True, related_name="user_object", db_index=True)
manager = models.ForeignKey(Manager, on_delete=models.SET_NULL, blank=True, null=True, related_name="manager")
first_name = models.CharField(max_length=30, null=True, verbose_name="employee first name")
last_name = models.CharField(max_length=40, null=True, verbose_name="employee last name")
the EmployeeForm looks like this
class EmployeeForm(forms.ModelForm):
dob = forms.DateField(widget=DateInput(format="%Y-%m-%d"), input_formats=("%Y-%m-%d",))
manager = forms.ModelChoiceField(queryset=Manager.objects.filter(groups__name="manager1").values_list("first_name", "last_name"))
def __init__(self, *args, **kwargs):
super(EmployeeForm, self).__init__(*args, **kwargs)
class Meta:
model = Application
exclude = ("on_hold")
the form is genearated in template and creates an employee form with a select field of Managers who match group “manager1”
The problem is that the Manager select field shows a tuple like this,
Select your Manager:
- (‘Joe’, ‘Smith’)
- (‘Fred’, ‘Jones’)
etc
How can I format it so it shows first and last names normally and not show a tuple in the option value?
ie
- Joe Smith
- Fred Jones
etc
my template field is genearated like this
<div class="row mt-3">
<div class="col"><label>Your Manager </label></div>
<div class="col">{% bootstrap_field form.manager show_label=False %}</div>
</div>
ps - I also noticed that the generated Select field option is a tuple, not the ID of the manager,
<option value="('Joe', 'Smith')">('Joe', 'Smith')</option>
I want it to be like this, ie, the PK of the Manager as the value
<option value="26">Joe Smith</option>