i want to filter some object related to current logined user in
forms.py, the key code is:
choices = [(str(x.id), x.name) for x in
Category.objects.filter(user__id__exact=request.user.id)]
but i got this error:
Exception Type: NameError
Exception Value: global name 'request' is not defined
Exception Location: d:\django\mysite\blog\forms.py in __init__, line
16
my question is how to select current user's object in the
forms.py,thanks!
full code as below:
class CreateEntryForm(forms.Form):
def __init__( self, *args, **kwargs ):
super( CreateEntryForm, self ).__init__( *args, **kwargs )
self.fields['category'] = forms.ChoiceField(
choices = [(str(x.id), x.name) for x in
Category.objects.filter(user__id__exact=request.user.id)]
)
category = forms.CharField(max_length=80, label=_('Category'))
title = forms.CharField(max_length=80, label=_('Title'))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---