私はdjango-friendsとdjango-messagesを使用しています。
カスタム作成フォームを変更して、次の情報、myfriendsを取得し、ユーザー名だけでなくフルネームも表示するようにしました。
私が抱えている問題の1つは、サインインしたユーザーとして自分自身にアクセスできないように見えることです。クエリを完了するには、ハードコーディングする必要があります。
class MyComposeForm(forms.Form):
"""
A simple default form for private messages.
"""
recipient = forms.ModelChoiceField(queryset=Friendship.objects.all(), label=_(u"Recipient"))
#recipient = forms.ModelChoiceField(queryset=User.objects.all(), label=_(u"Recipient"))
subject = forms.CharField(label=_(u"Subject"))
body = forms.CharField(label=_(u"Body"),
widget=forms.Textarea(attrs={'rows': '2', 'cols':'55'}))
def __init__(self, *args, **kwargs):
recipient_filter = kwargs.pop('recipient_filter', None)
super(MyComposeForm, self).__init__(*args, **kwargs)
### underneath here I have to hardcode with my ID to pull the info.
friends = Friendship.objects.filter(from_user=1)
self.fields['recipient'].choices = [(friend.to_user.pk, friend.to_user.get_full_name()) for friend in friends]
if recipient_filter is not None:
self.fields['recipient']._recipient_filter = recipient_filter
ユーザーインスタンスにアクセスするにはどうすればよいですか?
追加request
し__init__
て使用してみましrequest.user
たが、うまくいかないようです。
何か案は?