我想将我的成就模型的“order”整数字段设置为成就中对象的当前计数。order字段用于对成果进行排序,用户可以对其进行更改。现在我默认为1。在
class Achievement(models.Model):
title = models.CharField(max_length=50, blank=True)
description = models.TextField()
order = models.IntegerField(default=1) #Get the number of achievement objects
class Meta:
db_table = 'achievement'
ordering = ['order', 'id']
例如,如果我的数据库中已经有一个成就,不管顺序如何,下一个应该得到order=2。在
据我所知,您希望在
order
整型字段中有一个默认值1
,并将其与Achievment
的每个条目一起递增(功能与id
相同),但也允许用户更改它。在为此,您可以使用Django的^{} :
像这样:
相关问题 更多 >
编程相关推荐