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

The Archive Base Latest Questions

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

I have a querylist that returns possible solutions to a problem. The list returns

  • 0

I have a querylist that returns possible solutions to a problem. The list returns the results that I am expecting. I am trying to add a checkbox form that correlates to each item on the querylist. Its not too fancy, I just need to check the box and update the model. I have two models:

149 class TaskSolution(models.Model):                                                                                                           
150     solution          = models.TextField()                                                                                                  
151     submitter         = models.ForeignKey(User, null=True, blank=True)                                                                       
152     relatedtask       = models.ForeignKey(Task, null=True, blank=True)                                                                      
153     solutionnumber    = models.IntegerField(editable=False)                                                                                 
154     date_created      = models.DateTimeField(editable=False)                                                                                 
155     date_updated      = models.DateTimeField(editable=False)                                                                                
156     confimed_solution = models.BooleanField()                                                                                               
157     objects           = SolutionVoteManager()

160     def save(self, *args, **kwargs):                                                                                                        
161         if not self.id:                                                                                                                     
162             self.date_created = datetime.now()                                                                                              
163         self.date_updated = datetime.now()                                                                                                  
164         super(TaskSolution, self).save(*args, **kwargs)                                                                                     

166     def __unicode__(self):                                                                                                                  
167         return self.id                                                                                                                      

169     def __unicode__(self):                                                                                                                  
170         return "%s" % self.object_pk                                                                                                        

172     def __unicode__(self):                                                                                                                  
173         return self.solution  


184 class MarkedSolved(models.Model):                                                                                                           
185     is_solution      = models.BooleanField(verbose_name='')                                                                                 
186     related_idea     = models.ForeignKey(Idea, editable=False)                                                                              
187     related_task     = models.ForeignKey(Task, editable=False)                                                                              
188     related_solution = models.IntegerField(editable=False)                                                                                  
189     date_updated     = models.DateTimeField(editable=False)                                                                                 

191     def save(self, *args, **kwargs):                                                                                                        
192         self.date_updated = datetime.now()                                                                                                  
193         super(MarkedSolved, self).save(*args, **kwargs)                                                                                     

195     def __unicode__(self):                                                                                                                  
196         return self.id                                                                                                                      

198     def __unicode__(self):                                                                                                                  
199         return "%s" % self.object_pk                                                                                                        

201     def __unicode__(self):                                                                                                                  
202         return "%s" % self.is_solution

204 class MarkedSolved(ModelForm):                                                                                                          
205     class Meta:                                                                                                                             
206         model = MarkedSolved      

Now in my View I have the following queryset:

solution_list = TaskSolution.objects.filter(relatedtask__id=task_id) 

This is fine as it returns the solutions as expected. The issue I am now having is I would Like the MarkSolved form initial value to correlate with the solution_list value.

 393 if request.method == 'POST':                                                                                                                                                                                                                              
 394         mark_solved_form = PostMarkedSolved(data=request.POST, instance=solution_task)

Essentially I am looking for a query like this:

select * from markedsolved a, tasksolution b where a.related_solution=b.solutionnumber and a.related_solution=1 and b.solutionnumber=1 and a.related_task_id = 5 and b.relatedtask_id=5;

Where all the values match up from the two models in the queryset. That query returns the exact results I would like, but I am at a loss on now to populate the initial value based on the solution_list results.

  • 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:15:39+00:00Added an answer on June 13, 2026 at 8:15 pm

    I think the model MarkedSolved needs related field to TaskSolution model

    replce

    related_solution = models.IntegerField(editable=False)

    with

    related_solution = models.ForeignKeyField(TaskSolution)

    Tempalte

       {% for item in solved_list%}
            <input type = "checkbox" name="{{item.id}}" > {{item.solution}}
       {% endfor %}
    

    Views

     if request.method == 'POST':
          for soln in solutions_list: 
             solution_id = request.POST.get(str(soln.id))    
             if solution_id:
                MarkedSolved.objects.create(
                 is_solution = True,
                 related_task = Task.objects.get(id=task_id),
                 related_solution = soln
                )
    

    I didnt tested the above code, but this will gives you the idea

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

Sidebar

Related Questions

i have an sql query that has one unnamed column as a list of
I have a List with over 1000 unique entries and I want to form
I have a form that has disabled select box. I have this function in
I have a querydict that looks like the following: <QueryDict: {u'{content:aa,id:1}': [u'']}> How would
I have the following LINQ query: List<string> Types = (List<string>)Directory.GetFiles(@C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727) .Where(x => System.IO.Path.GetFileNameWithoutExtension(x).Contains(Microsoft)) .ToList<string>();
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
Have a painfully simple blog Post creator, and I'm trying to check if the
Well, I have implemented a distinct query in hibernate. It returns me result. But,
i have wrote a method that filters output with provided query and return it.
I have a template that has a button that posts just the button's name

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.