Django编辑数据库条目主键

时间:2014-07-31 01:07:07

标签: python database django primary-key

这就是全部,我想知道怎么做我可以编辑我的数据库上的主键,我已经尝试创建一个model.Admin with list_editable并设置'id'但它没有工作

class ArticleAdmin(admin.ModelAdmin):
list_display = ('article_title','article_body','article_state','id')
list_editable = ('id','article_state',)

想法?

1 个答案:

答案 0 :(得分:0)

要更改订单,您可以添加订单字段:

class Article(models.Model):
    order = models.IntegerField(default=0)

    class Meta:
        ordering = ['order']

    def save(self, *args, **kwargs):
        # Not quite sure you would want to do this but it's at least an option.
        if self.order == 0 and self.pk:
            self.order = self.pk