Django抛出“ValueError:int()的无效文字,基数为10:'user_comment_id'”

时间:2016-05-26 11:31:09

标签: django django-models

我正在尝试显示用户名和个人资料图片并获取错误,因为ValueError:int()的无效文字,基数为10:'user_comment_id'。请帮忙。

from django.contrib.auth.models import User
class Article(models.Model):
    pub_date = models.DateTimeField()
    headline = models.CharField(max_length=255)
    content = models.TextField()
    reporter = models.ForeignKey(Reporter,on_delete=models.CASCADE)
    vote = models.IntegerField(default=0)

UserProfile表

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    picture = models.ImageField(upload_to='profile_images',blank=True)

评论表

class Comment(models.Model):
    comment = models.TextField(max_length=1000)
    user  = models.ForeignKey(User,on_delete=models.CASCADE)
    article = models.ForeignKey(Article,on_delete=models.CASCADE)
    created_date = models.DateTimeField(default=timezone.now)

以下是我在shell上尝试的命令 导入所有模型,包括用户

a= Article.objects.get(pk=6)
c= a.comment_set.all()
for var in c:
    print var.user , var.user.userprofile.picture

错误

>  for i in c:          
...   print i.user , i.user.userprofile.picture
...
Traceback (most recent call last):
  File "<console>", line 2, in <module>
  File "C:\Python27\lib\site-packages\django\db\models\fields\related_descriptors.py", l
ine 167, in __get__
    qs = qs.filter(self.field.get_reverse_related_filter(instance))
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 790, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 808, in _filter_o
r_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1243, in add_
q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1263, in _add
_q
    current_negated, allow_joins, split_subq)
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1269, in _add
_q
    allow_joins=allow_joins, split_subq=split_subq,
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1203, in buil
d_filter
    condition = self.build_lookup(lookups, col, value)
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1099, in buil
d_lookup
    return final_lookup(lhs, rhs)
  File "C:\Python27\lib\site-packages\django\db\models\lookups.py", line 19, in __init__

    self.rhs = self.get_prep_lookup()
  File "C:\Python27\lib\site-packages\django\db\models\lookups.py", line 57, in get_prep
_lookup
    return self.lhs.output_field.get_prep_lookup(self.lookup_name, self.rhs)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 744, in
 get_prep_lookup
    return self.get_prep_value(value)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 976, in
 get_prep_value
    return int(value)
ValueError: invalid literal for int() with base 10: 'user_comment_id'
>>>

0 个答案:

没有答案