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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:10:12+00:00 2026-05-14T01:10:12+00:00

I have 2 arrays that I would like to render in a template, one

  • 0

I have 2 arrays that I would like to render in a template, one is the data to be output, the other is a formset for deleting items. since it seems django does not support boolean operators in the template tag, I have tried packaging the items, but they return the first item and the first form in 2 rows only.

How does one package such items so that they are rendered in one for loop.

my view

@login_required
def forums(request ):

    post = list(forum.objects.filter(child='0')&forum.objects.filter(deleted='0'))
    user = UserProfile.objects.get(pk=request.session['_auth_user_id'])
    newpostform = PostForm(request.POST)
    deletepostform = PostDeleteForm(request.POST)
    DelPostFormSet = modelformset_factory(forum, exclude=('child','postSubject','postBody','postPoster','postDate','childParentId'))
    readform = ReadForumForm(request.POST)
    if newpostform.is_valid():
        topic = request.POST['postSubject']
        poster = request.POST['postPoster']
        newpostform.save()
    newpostform = PostForm(initial = {'postPoster':user.id})
    post = list(forum.objects.filter(child='0')&forum.objects.filter(deleted='0'))

    else:
        newpostform = PostForm(initial = {'postPoster':user.id})

    if request.method == 'POST':
        delpostformset = DelPostFormSet(request.POST)
        if delpostformset.is_valid():
            delpostformset.save()

    else:
        delpostformset = DelPostFormSet(queryset=forum.objects.filter(child='0', deleted='0'))


    """if readform.is_valid():
        readform.save()
    else:
        readform = ReadForumForm()"""


    return render_to_response('forum.html', {'post':( post,delpostformset.forms), 'newpostform': newpostform, })

my Template

<table class="results">
<tr class="inner_results_header"><td >Title</td><td>Date/Time</td><td>Poster</td>      <td>Body</td><td><form method="post" id="form" action=""  class="usertabs accfrm"><input type="submit" value="Delete" /></td></tr>  
{{formset.management_form}}
{% for p, form in post   %}



{% url forum_view p.postID  as post_url%} 
<tr  class="inner_results {% if forloop.counter|divisibleby:2 %}evens{% else %}odds{% endif %}"><span onclick="document.location.href='{{post_url}}';"><td>{{ p.postSubject}}</td><td>{{p.postDate}}</td><td>{{ p.postPoster}}</td><td>{{ p.postBody|truncatewords:50}}</td></span><td>


{{ form.as_p }}


</td></tr> 

{% endfor %}

<tr class="inner_results_header"><td >Title</td><td>Date/Time</td><td>Poster</td> <td>Body</td><td><input type="submit" value="Delete" /></form></td></tr>  

  • 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-14T01:10:13+00:00Added an answer on May 14, 2026 at 1:10 am

    Use zip builtin. If both post and delpostformset.forms are iterables, zip will return a list of tuples. In view:

    post_and_form = zip(post, delpostformset.forms)
    

    and in template:

    {% for post, form in post_and_form %}
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an enum that I would like to randomly select a value from,
I have a one dimensional NumPy array: a = numpy.array([2,3,3]) I would like to
Once again, I have a problem for which I would like to shave off
I have a menu structure that outputs a list of favourite configuration items. In
I'm trying to merge two arrays that have some overlapping results and some that
I have an action in my controller that renders JSON back to the client:
I have seen a few variants of this nested UL array question on stackoverflow,
I'm getting this error when I deploy my app on Heroku: Started GET /collections/transect/search?utf8=%E2%9C%93&search%5Btagged_with%5D=village&commit=Search
I'm trying to come up with a standard way to create multiple forms for
I store all variables settings for some project in a class named Ini .

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.