Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
Django Form - Select dropdown

How do I Output both "id_no" and "name" [id_no - name] combined in dropdown select form. Can it be done directly to the form using {{form}} only.

Model:
class Employee(models.Model):
  id_no = models.CharField(unique = True,max_length=6)
  name = models.CharField(max_length=100)

Form:
class EmployeeForm(forms.ModelForm):
  class Meta:
   model = Employee
   fields = __all__
    
    
    
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Yes, it be done directly to the form using {{form}} implementing str :

class Employee(models.Model):
    id_no = models.CharField(unique = True,max_length=6)
    name = models.CharField(max_length=100)

    def __str__(self):
        return f"{self.id_no} - {self.name}"

But not on EmployeeForm because this form doesn't have a drop down to pick an employee. You will see it on a modelFrom for a form with a ForeignKey to employee.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!