Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3307352
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:23:47+00:00 2026-05-17T21:23:47+00:00

I am using django-friends and django-messages. I have modified my custom compose form to

  • 0

I am using django-friends and django-messages.

I have modified my custom compose form to pull the following information, myfriends and also display their fullnames instead of just usernames.

One problem I have is that I cannot seem to access myself as a signed in user, to complete the query, I have to hard code it.

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

How do I access my user instance?

I have tried adding request to __init__ and using request.user but this does not seem to work.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:23:48+00:00Added an answer on May 17, 2026 at 9:23 pm

    You can pass request in your form like:

    form = MyComposeForm(request.POST,request) 
    

    in your views.py file, where the form has been instantiated. You can then access the request object as:

    requestObj = kwargs.pop('request', None)
    

    your code will look like:

    def __init__(self, *args, **kwargs):
        recipient_filter = kwargs.pop('recipient_filter', None)
        requestObj = kwargs.pop('request', None)
        super(MyComposeForm, self).__init__(*args, **kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I using Django and a generic view django.views.generic.create_update.create_object I have a model form wich
Using django-contact-form , I have overridden the form class: from contact_form.forms import ContactForm from
using django 1.4 I have a model with a datetimefield. I imported django.utils.timezone to
I am using django-threadedcomments , however the question also applies generally to sorting a
I am using Django with Postgres and Heroku. and I have a post table
Using django 1.4 and have seen that when you use startproject it now creates
Using Django with a PostgreSQL (8.x) backend, I have a model where I need
I am working on a cookbook website using django and have run into a
I'm using Django and Tastypie to create a RESTful web app. I have a
Im using Django 1.2.3. I have login functionality in my site using django.contrib.auth.views.login .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.