title: Django : How to exclude form field if the user is staff?
body: <p>How to exclude form fields if the user is not staff ? I tried this but didn't work , giving an error : </p>
  
  <p><code>global name 'user' is not defined</code></p>
  
  <pre><code>class PostForm(ModelForm):
  
      class Meta:
          model = Photo
          exclude = ['author','featured','published']
  
      def __init__(self, *args, **kwargs):
          published = kwargs.pop('published', None)
          super(PostForm, self).__init__(*args, **kwargs)
          if not user.is_staff:
             del self.fields['published']
  </code></pre>
  
  <p>view.py </p>
  
  <pre><code>def addpost(request):
  
      if request.method == 'POST': 
          form = PostForm(request.POST,request.FILES,user=request.user) 
          if form.is_valid():
  
              post = form.save(False)
              post.author = request.user
              form.save()
  
              return HttpResponseRedirect(reverse('insight.content.views.index', ))
  
      else:
          form = PostForm(user=request.user)
  
  
      ispost = True
      return render_to_response('form_add_place.html', {'form': form,'ispost':ispost},context_instance=RequestContext(request))
  </code></pre>