【发布时间】:2011-06-04 19:09:05
【问题描述】:
我不知道这里发生了什么...我只想检查模型字段的值,然后相应地对其进行更新...感谢任何帮助或见解!
型号:
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
beta = models.CharField(max_length=1, blank=True, null=True)
查看:
from internal.accounts.models import UserProfile
from django.contrib.auth.models import User
@login_required
def beta_testers(request):
user = User.objects.get(username=request.user.username)
user_profile = user.get_profile()
count = UserProfile.objects.filter(beta='1').count()
if count < 50 and not user_profile['beta']:
user_profile['beta'] = '1'
user_profile.save()
错误:
TypeError at /utilities/beta-signup/
'UserProfile' object is unsubscriptable
Request Method: GET
Request URL: http://localhost/utilities/beta-signup/?x=1&y=15
Django Version: 1.2.1
Exception Type: TypeError
Exception Value:
'UserProfile' object is unsubscriptable
Exception Location: C:/django\internal\cms_helper\views.py in beta_testers, line 284
【问题讨论】:
标签: django django-models django-views