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 8721031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:09:25+00:00 2026-06-13T07:09:25+00:00

In my ModelForm’s save() method I am accessing self.changed_data and I would like to

  • 0

In my ModelForm’s save() method I am accessing self.changed_data and I would like to do something like:

changes_moderated_dict.update(dict(
    [(i, staff.profile.user.__dict__[i]) 
    for i in changed_data 
    if i in  staff.profile.user.__dict__]))

which updates changes_moderated_dict with staff.profile.user key/value pairs if the key is found in changed_data. changes_moderated_dict is basically used to store all the field changes made to this particular model inside the form (for later processing and serialization).

This works all fine as long as the staff.profile.user is not a foreign key relationship in which case the filed name has a _id suffix and would not match up with the self.changed_data field name which is the attribute name as it appears in the model (without _id).

Is there a way do resolve the foreign key attribute inside a model’s __dict__ to it’s actual name so that the above method still works?

  • 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-13T07:09:25+00:00Added an answer on June 13, 2026 at 7:09 am

    I’m not sure what the goal of accessing user.__dict__ is, but if it is to check the model fields you can do something like this:

    u = staff.profile.user
    model_field_names = map(lambda f:f.name, u._meta.fields)
    changes_moderated_dict.update(dict(
        [(i, getattr(u, i, None))
        for i in changed_data
        if i in model_field_names]))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a modelform to extend a user's profile. I would like previously
When using ModelForm Within forms.py it would save a lot of time, since there
My form field looks something like the following: class FooForm(ModelForm): somefield = models.CharField( widget=forms.TextInput(attrs={'readonly':'readonly'})
I have something like this in form : class EventForm(ModelForm): reg_due_date = forms.DateTimeField(input_formats=('%d/%m/%Y %H:%M',),
I have this form.py: from shortcut import get_timezone class HostCreateForm(forms.ModelForm): def save(self, commit=True): host1
I currently have a ModelForm set up in Django, but would like to make
In my implementation of ModelForm, I would like to perform different types of validation
My form: class AssessmentForm(ModelForm): def save(self, commit=True, request=None, *args, **kwargs): print 'request.user.id:',request.user.id instance =
I'm having trouble overriding a ModelForm save method. This is the error I'm receiving:
In a Django ModelForm, you can change the widget type of a field like

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.