我正在尝试在Django网站上实施评级系统。 我只用一颗星(booleanfield)false / true来完成我的评分:
<!-- 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()
..........
答案 0 :(得分:1)
您可以使用
// curve.vue
<template>
<autocomplete v-model="curve.y"></autocomplete>
</template>
<script>
import Autocomplete from './autocomplete'
export default {
name: 'Curve',
props: {
value: Object
},
data() {
return { currentValue: this.value }
}
computed: {
curve() { return this.currentValue }
},
watch: {
'curve.y'(val) {
this.$emit('input', this.currentValue);
}
},
components: { Autocomplete }
}
</script>
// autocomplete.vue
<template>
<input type="text" v-model="content"/>
</template>
<script>
export default {
name: 'Autocomplete',
props: {
value: {
type: String,
required: true
}
},
data() {
return { currentValue: this.value };
},
computed: {
content: {
get() { return this.value },
set(newValue) {
this.currentValue = newValue;
this.$emit('input', this.currentValue);
}
}
}
}
</script>