models.py
class User(EmbeddedDocument,Document):
''' Store user's info'''
user_id = IntField(unique = True)
user_name = StringField(unique =True,primary_key =True,max_length = 256)
user_secret = StringField(max_length=256)
ビュー.py
def register(request):
accept = False
un = request.REQUEST.get('username')
ps = request.REQUEST.get('password')
if not un:
raise ValueError('The given username must be set')
if not ps:
raise ValueError('The given password must be set')
if isUserExistByName(un):
o='The name has been registered.'
raise TAUTHException(o)
else:
uid = getNextCount(UserCount)
ps_hash = password_hash(un,ps)
user = User(user_id = uid,user_name = un,user_secret = ps_hash)
user.save(cascade = True)
accept = True
result = {'accept':accept}
msg = urlencode(result)
return HttpResponse(msg)
ユーザーを登録しようとすると、プログラムは正常に実行されますが、mongodb はこのユーザーを保存しません。不思議なことに、User を
class User(Document):
''' Store user's info'''
user_id = IntField(unique = True)
user_name = StringField(unique =True,primary_key =True,max_length = 256)
user_secret = StringField(max_length=256)
それはうまく動作し、mongodb はユーザーを正常に保存します。