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

306
Views
Changing the default placeholder in a Django model form for a ForeignKey

I have my code set up as follows:

models.py

class Category(models.Model):
    name = models.CharField(max_length=255)

class Product(models.Model):
    category = models.ForeignKey(Category)

forms.py

class ProductForm(forms.ModelForm):
    class Meta:
        model = Product
        fields = ('category',)
        widgets = {
            #'category' : forms.TextInput(attrs={'placeholder' : 'Select the category'}),
        }

Basically, right now, without the widgets part, I get -------- as the placeholder for this field. However, I want to get 'Select the category', how can I do this? Thanks!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can set custom placeholder using empty_label field:

class ProductForm(forms.ModelForm):
    category = forms.ModelChoiceField(queryset=Category.objects.all(), empty_label='Select the category')

    class Meta:
        model = Product
about 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!