with django, how to write a grdview or table to show information and add a button or link in each row for approval?

16 views
Skip to first unread message

meInvent bbird

unread,
May 26, 2016, 10:53:07 PM5/26/16
to Django users
with django, how to write a grdview or table to show information and add a button or link in each row for approval?

jorr...@gmail.com

unread,
May 27, 2016, 3:25:35 AM5/27/16
to Django users
Sounds like Formsets is what you are looking for.

meInvent bbird

unread,
May 27, 2016, 4:09:53 AM5/27/16
to Django users
i write with this method, but nothing is displayed, only blank page,

however there are data shown in console

where is wrong?

{% block content %}
    <table>
    {% for post in posts %}
      <tr>
        <td>
          post.project
        </td>
        <td>
          post.company
        </td>
      </tr>
    {% endfor %}
    </table>
{% endblock %}

views.py
def post_detail(request):
    posts = []
    with open('/home/martin/Downloads/site1/site1/reg/newusers.csv', 'rb') as csvfile:
     reader = csv.DictReader(csvfile)
     for row in reader:
      if len(row['name'].strip()) > 0 and len(row['project'].strip()) > 0 and len(row['initial password'].strip()) > 0 and len(row['email address'].strip()) > 0 and len(row['company'].strip()) > 0 and len(row['userType'].strip()) > 0 and len(row['businessType'].strip()) > 0 and len(row['contact'].strip()) > 0 and len(row['name'].strip()) > 0:
       eachbracket = {'name' : row['name'].strip(), 'project' : row['project'].strip(), 'businessType' : row['businessType'].strip(), 'userType' : row['userType'].strip(), 'company' : row['company'].strip()}
       posts = posts + [eachbracket];
    print posts
    return render(request, 'approval.html')

meInvent bbird

unread,
May 27, 2016, 4:12:46 AM5/27/16
to Django users
after changed to     return render(posts, 'approval.html')
got error
'list' object has no attribute 'META'

def post_detail(request):
    posts = []
    with open('/home/martin/Downloads/site1/site1/reg/newusers.csv', 'rb') as csvfile:
     reader = csv.DictReader(csvfile)
     for row in reader:
      if len(row['name'].strip()) > 0 and len(row['project'].strip()) > 0 and len(row['initial password'].strip()) > 0 and len(row['email address'].strip()) > 0 and len(row['company'].strip()) > 0 and len(row['userType'].strip()) > 0 and len(row['businessType'].strip()) > 0 and len(row['contact'].strip()) > 0 and len(row['name'].strip()) > 0:
       eachbracket = {'name' : row['name'].strip(), 'project' : row['project'].strip(), 'businessType' : row['businessType'].strip(), 'userType' : row['userType'].strip(), 'company' : row['company'].strip()}
       posts = posts + [eachbracket];
    print posts
    return render(posts, 'approval.html')


got error
'list' object has no attribute 'META'


On Friday, May 27, 2016 at 3:25:35 PM UTC+8, jorr...@gmail.com wrote:

meInvent bbird

unread,
May 27, 2016, 5:05:12 AM5/27/16
to Django users
currently the error is 

dictionary update sequence element #0 has length 5; 2 is required


def post_detail(request):
    posts = []
    with open('/home/martin/Downloads/site1/site1/reg/newusers.csv', 'rb') as csvfile:
     reader = csv.DictReader(csvfile)
     for row in reader:
      if len(row['name'].strip()) > 0 and len(row['project'].strip()) > 0 and len(row['initial password'].strip()) > 0 and len(row['email address'].strip()) > 0 and len(row['company'].strip()) > 0 and len(row['userType'].strip()) > 0 and len(row['businessType'].strip()) > 0 and len(row['contact'].strip()) > 0 and len(row['name'].strip()) > 0:
       eachbracket = {'name' : row['name'].strip(), 'project' : row['project'].strip(), 'businessType' : row['businessType'].strip(), 'userType' : row['userType'].strip(), 'company' : row['company'].strip()}
       posts = posts + [eachbracket]
    #posts = posts1
    print posts
    return render(request, 'approval.html', posts)


On Friday, May 27, 2016 at 3:25:35 PM UTC+8, jorr...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages