0
user    = models.ForeignKey(User,)

I have a user foreignkey in models.py

if request.user.is_authenticated():
    feedback.user = request.user
else:
    feedback.user = 'something'

In views.py, If user logged in feedback.user area, write username else write something there. How can I do this in Django.

I was trying to django-feedback and it was like just

feedback.user = request.user

Like this, it was giving the error below.

Cannot assign "<django.contrib.auth.models.AnonymousUser 
object at 0x2dbcf50>": "Feedback.user" must be a "User" instance

I am working on localhost. Any idea?

4

1 回答 1

1

要么要求用户登录以查看视图,要么自己处理并分配无。

于 2011-06-16T11:34:09.527 回答