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

198
Views
How can I enter numbers in the bar on the django form?

What you want to achieve

イメージ説明

I want to input numbers in the django form like this.

Current code

class Comment_movie_CreateForm (ModelForm):
    class Meta:
        model = Comment_movie
        fields = ('comment','stars')
    comment = forms.CharField (required = False, label ='comment', max_length = 1000)
    stars = forms.FloatField (required = False, label ='stars', widget = forms.TextInput (
       attrs = {'type':'range','id':'form_homework', "class": "no_resize",'min': '0','max': '10','step': '0.1' })))
    def clean (self):
        cleaned_data = super (). clean ()
        return cleaned_data
    def clean_stars (self):
        stars = self.cleaned_data ['stars']
        if stars! = None:
            if stars <0 or stars> 10:
                raise forms.ValidationError ("The rating input is incorrect.")
            return stars
        else: else:
            raise forms.ValidationError ("The rating input is incorrect.")
    def clean_comment (self):
        comment = self.cleaned_data ['comment']
        if len (comment)> 1000:
            raise forms.ValidationError ("There are too many characters.")
        elif len (comment) == 0:
            raise forms.ValidationError ("Please enter the characters.")
        return comment
    def __init__ (self, * args, ** kwargs):
        super () .__ init__ (* args, ** kwargs)
        self.label_suffix = ""
<form method="POST" enctype="multipart/form-data">
        {% csrf_token %}
        {{ form }}
        {% if comment_tv %}
        <button type="submit">Edit Comment</button>
        <button type="submit" name="action" value="delete">Delete Comment</button>
        {% else %}
        <button type="submit">Post Comment</button>
        {% endif %}
    </form>

What you want to ask

How would you change it to look like the photo? Is this adjusted with CSS? Or is it javascript?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Easy way is:

attrs = {'type':'range', ...

but it is not works everywhere https://www.w3schools.com/tags/att_input_type_range.asp

about 4 years ago · Santiago Gelvez 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!