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
  • 1 View
  • 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 two arrays that I would like to compare and ultimately wind up
I have two arrays of data that I'm trying to amalgamate. One contains actual
I have a Rails Table, called Sales, that I would like to render in
I have an array that I would like to sort using a date field
I have an SHA-1 byte array that I would like to use in a
PHP: I have made up a function that returns an array. I would like
I have two arrays that I create like this: public int GameBoard[][] = new
I've made an array in my controller with the items that I would like
I have two models that I would like to present in a single Yii
I have the $user array that contains data with special characters. It seems 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.