我正在尝试从这里实现orderedmodel:https ://github.com/kirelagin/django-orderedmodel
但它因 DatabaseError 而失败Exception Value: no such column: qrgame_place.order
文档没有说明模型应该包含该字段order
,所以我想父类应该实现该字段?[编辑:是的,它是。试过...]
以下是 django 文件中的一些重要片段:
# models.py
import hashlib
import random
from django.db import models
from orderedmodel import OrderedModel
class Place(OrderedModel):
name = models.CharField(max_length=100)
clue = models.CharField(max_length=300)
code = models.CharField(max_length=7, editable=False)
def __unicode__(self):
return self.name
def save(self):
# Need a secret identifier for url. Using a hashed name (which
# is also secret until found. So no need to obscure more)
if not self.id:
hashsrc = self.name.encode('utf-8')
self.code = unicode(hashlib.sha1(hashsrc).hexdigest()[:7])
super(Place, self).save()
# admin.py
from django.contrib import admin
from qrgame.models import Place
from orderedmodel import OrderedModelAdmin
class PlaceAdmin(OrderedModelAdmin):
list_display = ['name', 'clue', 'reorder']
admin.site.register(Place, PlaceAdmin)
# settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'orderedmodel',
'qrgame',
)
我python manage.py syncdb
在实现这个之后就跑了。
知道有什么问题吗?(Django 版本为 (1, 4, 1, 'final', 0))