請幫忙解決問題。如何獲取字段繼承模型?
我有一個模型:
class UserProfile(User):
gender = models.ForeignKey(
Gender,
verbose_name='Пол',
blank=True,
null=True,
)
nickname = models.CharField(
'Отображаемое имя',
max_length=50,
blank=False,
)
phone = models.CharField(
max_length=50,
blank=False,
)
skype = models.CharField(
max_length=50,
blank=False,
)
other = models.TextField(
max_length=500,
blank=False,
)
avatar = models.ImageField(
upload_to='userprofile/avatar/',
blank=True,
null=True,
)
objects = UserManager()
@classmethod
def get_new_authors_entries(self, cut_begin=0, cut_end=2):
return self.objects.filter(is_active=1, is_superuser=0)[cut_begin:cut_end]
方法get_new_authors_entries()返回以下字段:
[
{
"fields":
{
"skype": "dfsdf",
"user_permissions": [],
"other": "zzzz",
"nickname": "\u0418\u0432\u0430\u043d \u0422\u0443\u0440\u0433\u0435\u043d\u0435\u0432 \u0451\u043f\u0442\u0430",
"gender": 1,
"avatar": "",
"phone": "2014-0921",
"groups": []
},
"model": "app_accounts.userprofile",
"pk": 4
},
.....,
.....,
....
]
,但我需要的字段的值: 'date_joined','用戶名','電子郵件'
UserProfile從User繼承。我不明白爲什麼我不能到田裏訪問:「date_joined」,「用戶名」,「電子郵件」
views.py(片段):
new_authors = UserProfile.get_new_authors_entries(cut_begin=page_new_authors, cut_end=page_new_authors + 2)
result = serializers.serialize('json', new_authors)
return HttpResponse(json.dumps(result), content_type='application/json')
在我的手機上,對不起 – 2014-10-11 17:05:17