I am new to the django, and I am working on a data science project that aims to create a web application that interact with user in order to gather same data in first step, and after that, make a recommendation to the user.
My issue is that I have a model Countries
that has country_name
, user_rating
, and user_id
as ManyToMany
fields, how I can give the user the choice to rate country name using the stars rating and then save the rating in user_rating
field ?
Asked
Active
Viewed 443 times
1

Error - Syntactical Remorse
- 7,468
- 4
- 24
- 45

Ayoub EL MAJJODI
- 161
- 1
- 10
-
You can use a `Stars` widget: https://pypi.org/project/django-starfield/ – Willem Van Onsem Jul 24 '19 at 12:15
1 Answers
2
You can use the django-starfield package [PyPi] to use the Stars
widget. You can install this - for example in your local environment, with:
pip3 install django-starfield
then you can use this in your form, like:
from django import forms
from django_starfield import Stars
class SomeForm(forms.Form):
user_rating = forms.IntegerField(widget=Stars)

Willem Van Onsem
- 443,496
- 30
- 428
- 555
-
2how I can increate the size of stars and to rate should start from the left to right – Ayoub EL MAJJODI Jul 27 '19 at 14:52
-
@AyoubELMAJJODI You can override the `stars.html` template with your own, or add CSS styling. Every rating widget gets a specific `id` (just use your favourite browser's inspector to discover it). – Dominik George Dec 19 '20 at 19:36
-
if user_rating is a field and I want to change it using widget. How should I write it? – NobinPegasus Dec 02 '21 at 22:53