我有一个如下模型:
class StaffProfile(models.Model):
user = models.ForeignKey(User)
maas = models.FloatField()
maas_gunu = models.CharField(max_length=5)
Run Code Online (Sandbox Code Playgroud)
当我尝试使用如下代码插入数据时:
staffprofilesay = StaffProfile.objects.filter(user = user_id).count()
if staffprofilesay > 0:
staffprofile = StaffProfile.objects.get(user = user_id)
else:
staffprofile = StaffProfile()
staffprofile.user = user_id
staffprofile.maas = calisan_formu.cleaned_data["maas"]
staffprofile.maas_gunu = calisan_formu.cleaned_data["maas_gunu"]
staffprofile.save()
Run Code Online (Sandbox Code Playgroud)
我收到这样的错误:
Cannot assign "u'1'": "StaffProfile.user" must be a "User" instance.
Run Code Online (Sandbox Code Playgroud)
我应该做些什么?
PS:我正在使用Django的用户模型
我有一个如下查询:
today = datetime.datetime.now()
month = today.month
print month
Run Code Online (Sandbox Code Playgroud)
它输出:
3
Run Code Online (Sandbox Code Playgroud)
我想显示月份名称,如"March".我该怎么办?
我希望在约会后的某个月找到,但我不知道如何.
让我说我有这个日期:
08.03.2012
Run Code Online (Sandbox Code Playgroud)
我想在一个月后的那个日期自动找到:
08.04.2012
Run Code Online (Sandbox Code Playgroud)
有谁知道这是怎么做到的吗?
我有一个对象列表如下所示:
[{'id': 17L,
'price': 0,
'parent_count': 2},
{'id': 39L,
'price': 0,
'parent_count': 1},
{'id': 26L,
'price': 2.0,
'parent_count': 4},
{'id': 25L,
'price': 2.0,
'parent_count': 3}]
Run Code Online (Sandbox Code Playgroud)
我想对对象进行'parent_count'排序,看起来像这样:
[{'id': 39L,
'price': 0,
'parent_count': 1},
{'id': 17L,
'price': 0,
'parent_count': 2},
{'id': 25L,
'price': 2.0,
'parent_count': 3},
{'id': 26L,
'price': 2.0,
'parent_count': 4}]
Run Code Online (Sandbox Code Playgroud)
有谁知道一个功能?
假设我有一个电话号码:
05395042123
我想将其转换为以下格式:
xxxx xxx xx xx
我该怎么做?有人有功能吗?