Answer the question
In order to leave comments, you need to log in
What is the correct way to display stars in Django reviews?
Hello.
Task: A person leaves a review (text) and the number of stars (number), and this information appears on the site: text - text, and the numbers are replaced by stars (image) (number 3 = three stars, etc.).
As a result:
I did it like this:
1) I added a method to the model that displays the number of pictures (stars), depending on the number that the person gives us.
class Mention(models.Model):
mentionn = models.ForeignKey(Step, on_delete=models.CASCADE)
mention_text = models.TextField()
mention_digit = models.IntegerField()
def get_star(self):
if self.mention_digit == 1:
return '<img src="../static/bakot/imagination/starfull.ico">'*1
elif self.mention_digit == 2:
return '<img src="../static/bakot/imagination/starfull.ico">'*2
elif self.mention_digit == 3:
return '<img src="../static/bakot/imagination/starfull.ico">'*3
elif self.mention_digit == 4:
return '<img src="../static/bakot/imagination/starfull.ico">'*4
elif self.mention_digit == 5:
return '<img src="../static/bakot/imagination/starfull.ico">'*5
else:
return self.mention_digit
<div class="small-12 medium-12 large-6 columns">
<ul class="menu pdding_h44">
<p>{{ men.get_star|safe }}</p>
</ul>
</div>
return '<img src="{% static "bakot/imagination/starfull.ico" %}">'*4
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question