単純なdjangoクエリが機能せず、なぜだろうと思っています
models.py
class Entry(models.Model):
headline= models.CharField(max_length=200,)
body_text = models.TextField()
author=models.ForeignKey(settings.AUTH_USER_MODEL, related_name='entryauthors')
pub_date=models.DateTimeField(auto_now_add=True)
def __str__(self):
return u'%s %s %s %s %s %s %s' % (self.headline, self.body_text, self.author, self.pub_date)
djangoシェルまたは私の見解で私は試しました
itemstosell = Entry.objects.get(author=username)[:4]
その結果:
Exception Type: ValueError
Exception Value: invalid literal for int() with base 10: 'john'
作成者は外部キーであるため、整数である可能性が高いユーザーモデルの主キーへの参照になります。あなたがすべきこと
itemstosell = Entry.objects.get(author__username=username)[:4]
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加