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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:55:26+00:00 2026-05-23T09:55:26+00:00

I feel my problem is quite obvious and has trivial solution, but I can’t

  • 0

I feel my problem is quite obvious and has trivial solution, but I can’t find it for few hours…

for realistic example let’s imagine I have next models:

class Report(models.Model):
    title = models.CharField(max_length=60)
    author = models.ForeignKey(User)
    posts = models.ManyToManyField(Post)

class Post(models.Model):
    title = models.CharField(max_length=100)
    author = models.ForeignKey(User)

So there are reports and posts. Posts can be associated with some report.
And there is following form for bounding/unbounding posts to reports.

class AddPostsToReport(ModelForm):
    def __init__(self, user, *args, **kwargs):
        super(AddPostsToReport, self).__init__(*args, **kwargs)
        self.fields['posts'] = forms.ModelMultipleChoiceField(
             queryset=Post.objects.filter(author=user),
             required=False, 
             widget=forms.CheckboxSelectMultiple)

    class Meta:
        model = Report
        fields = ('posts', )

So I pass additional parameter (user) to form and when user opens page with this form he can only bound/unbound his own posts.

Everything works fine except one thing: when user saves form – all other users’ posts which were before bound to that report become unbound. That is not what I need. I need that user can bound/unbound only his own posts to the report, but other users’ posts don’t reset their state.

Thank for any help.

EDIT: here is the view (it’s not the real view, but the logic of real view is exactly the same)

@login_required
def report_add_posts(request, report_id):
    report = get_object_or_404(Report, pk = report_id)

    if request.method == 'POST':
        form = AddPostsToReport(request.user, request.POST, instance = report)

        if form.is_valid():
            form.save()

            return HttpResponseRedirect(reverse(...))
    else:
        form = AddPostsToReport(request.user, instance = report)

    return render_to_response('report/page_with_form_to_add_posts.html', 
                              { 'form': form,
                                'report': report }, 
                              context_instance=RequestContext(request))
  • 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-23T09:55:26+00:00Added an answer on May 23, 2026 at 9:55 am

    I do not know of a “very easy” way to solve your problem. I would have used myform.save(commit=False) (from the view) and instead of calling the built in myform.save_m2m(), call a custom AddPostsToReport.save_posts() method that loops through self.instance['posts'], removing posts for the specified user not in self.cleaned_data['posts'] and later add the remaining new posts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like this is a common problem but nothing I've researched has worked
I do have a solution for the following problem but it's quite ugly and
I feel this is an awfully obtuse question to ask, but strangely, this problem
Feel free to close and/or redirect if this has been asked, but here's my
I've been trying to solve this problem for quite sometime but I am having
I feel quite limited by the default ContextMenuStrip, as it only can contain buttons,
I feel that this is likely a common problem, but from my google searching
I have quite common problem, but no idea how to solve it in practice
I have searched in Apple's iOS dev center but couldn't find anything quite right.
I feel my problem is relatively simple. I'm new to the Zend framework and

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.