我正试图在Django网站上实施一个评级系统。我做了我的评级只有一个明星(布尔兰菲尔德)假/真:
<!-- Favorite Album -->
<a href="{% url 'music:favorite_album' album.id %}" class="btn btn-default btn-sm btn-favorite" role="button">
<span class="glyphicon glyphicon-star {% if album.is_favorite %}active{% endif %}"></span>
</a>这是我的专辑模型:
class Album(models.Model):
user = models.ForeignKey(User, default=1)
artist = models.CharField(max_length=250)
album_title = models.CharField(max_length=500)
genre = models.CharField(max_length=100)
album_logo = models.FileField()
is_favorite = models.BooleanField(default=False)所以,我想知道如何改变这个评级,所以我将能够选择从1到5(在数字),以评级的专辑。通过这个,专辑模型应该是这样的--我想:
..........
is_favorite = models.IntegerField()
..........发布于 2017-09-24 04:49:24
您可以使用
Rating_CHOICES = (
(1, 'Poor'),
(2, 'Average'),
(3, 'Good'),
(4, 'Very Good'),
(5, 'Excellent')
)
is_favorite = models.IntegerField(choices=Rating_CHOICES, default=1)https://stackoverflow.com/questions/46386655
复制相似问题