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

  • Home
  • SEARCH
  • 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 8781569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:20:14+00:00 2026-06-13T20:20:14+00:00

I used Django’s generic createview for my model from myproject.app.forms import PersonForm class PersonMixin(object):

  • 0

I used Django’s generic createview for my model

from myproject.app.forms import PersonForm
class PersonMixin(object):
    model = Person
    form_class = PersontForm

class PersonCreateView(PersonMixin, CreateView):
    pass

This works perfectly for displaying a create view of Person with my custom form. However, I have a field in the form that I want to pre-populate with a value. I found this answer: Set initial value to modelform in class based generic views

However, my pre-populated value comes from the profile for request.user. How do I access the request in PersonCreateView and pass that to the form?

  • 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-06-13T20:20:16+00:00Added an answer on June 13, 2026 at 8:20 pm

    In any of the class methods you can access the request using self.request. So your user profile will be accessible with self.request.user.

    Building on the link you provided you will be able to use self.request.user in your get_initial method to set the value.

    ie.

    def get_initial(self):
        return { 'value1': self.request.user }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used django-mptt version (0,5,'+dev') My model looks like: class Comment(MPTTModel): content = models.CharField(max_length
I have a django app which is used for managing registrations to a survey.
I am using django 1.3.1 and satchmo 0.9.2. I used the default model that
I've used django-mptt to model the sections and sub-sections etc of the headings I
I've used Django's inspectdb command in the past, which gives you models from an
I've used Django forms. I have this function in views.py : def func(request): if
I have java sdk 1.7. I've always used django/python for web development, this will
Do you know the default isolation level of the transactions used in Django? Is
I have an apps and I am making used of django admin, but my
I have used httpclient to call a restapi written in django. It returned the

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.