0

How to initialize the email form with from_email address which is the current user's email address in django. I am using post-office application and wish to populate the from email address. How can the initial value be set as:

def __init__(self,*args,**kwargs):
        self.base_fields['from_email'].initial = 'hi@s.com'
       super(EmailForm, self).__init__(*args, **kwargs)

But the email id should vary dynamically. The request object is available in the changelist_view for the EmailAdmin and not in the ModelForm to take advantage of.

user956424
  • 1,611
  • 2
  • 37
  • 67

1 Answers1

0

This looks like a similar question: How can I get the username of the logged-in user in Django?

For your case, retrieve the user email address, and pass that in the request context to the template. You don't need to subclass anything

def my_view(request):
    if request.user.is_authenticated():
        email = request.user.email
Community
  • 1
  • 1
joel goldstick
  • 4,393
  • 6
  • 30
  • 46
  • http://stackoverflow.com/users/469072/joel-goldstick I am using the django-postoffice application where I use the Email model. I know how to get the current user mail address in the view but not for form init – user956424 Aug 11 '14 at 11:48
  • I want something similar to this http://stackoverflow.com/questions/8841502/how-to-use-the-request-in-I a-modelform-in-django?answertab=oldest#tab-top – user956424 Aug 11 '14 at 12:22