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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:43:17+00:00 2026-06-14T21:43:17+00:00

I’ve been struggling for a few day with this. I’m using django Python and

  • 0

I’ve been struggling for a few day with this.

I’m using django Python and all my objects have an abstract object that the user can’t change and can’t see in the pages, but he choses when he logs in.
So when he logs in, he enters user, password and select this object and I want to make sure that everything inside the pages have that object related, so when he logs in with another instance doesn’t see the previous ones.

Here it is my model: (as you can predict, all my objects have commonObject)

class Model(models.Model):
    name = models.CharField(max_length=200)
    thing = models.IntegerField()
    commonObject = models.ForeignKey(commonObject, editable=False)

Now my problem is that I can not save the commonObject. Please keep in mind that I’m using django-smarter, here it is the add_view code

action = self.action
form_kwargs = self.get_form_kwargs(action, request, *args, **kwargs)
if request.method == 'POST':
    form = self.get_form(action=action,
                        data=request.POST,
                        files=request.FILES,
                        **form_kwargs)
    if form.is_valid():
        form.cleaned_data['commonObject'] = pk.loads(request.session.get('commonObject'))
        print form.cleaned_data #Here the commonObject is the one that I want, but save doesn't seem to care
        instance = self.save_form(form)
        return self.add_success(request, instance)
else:
    form = self.get_form(action=action, **form_kwargs)
context = {'form': form}
return self.render_to_response(context)

My approaches were:

1) Save the commonObject in the save() method of the model rewriting it. The problem with this is that I can not access the request object (neither to save the common object in session or in another column of the User Object).

2) Changing form.clean_data doesn’t seem to be working. Within this approach, I tried to serialize the object, which I succesfully did with “pickable” but Models.py is taking as the real one the previous form rather than the one I changed.

3) Using pre_save and post_save, but I don’t have access to the request object in Models.py.

Could you please help me with this?

  • 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-14T21:43:19+00:00Added an answer on June 14, 2026 at 9:43 pm

    I think you cannot directly change data in form like you do. You must be save a form to create a data instance but not commit it yet then change the data you want. After you change everything you want then save it (with commit).

    e.g. (not test)

    if form.is_valid():
        instance = form.save(commit=False)
        instance.commonObject = pk.loads(request.session.get('commonObject'))
        instance.save()
        return self.add_success(request, instance)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.