Tuesday, June 24, 2014

Re: How do I Iterate database object querysets

Hello,

I would recommend to create a django form and feed the post data to this form.
Because 
1) the form will extract the post data for you
2) in the form you will be able the validate and clean the post data (you should definitively do that)

The code that saves the data to the form could also live in the form.


If the structure of the post data matches the structure of the database model closely, then a model form would be the easiest way.

Regards Roman


2014-06-24 21:33 GMT+02:00 G Z <zukeru@gmail.com>:
          for lis in Licenses.objects.values('code'):
             for post_value in insert_data:     
                 if lis in post_value:
                         license_tag += insert_data[lis] + ','

so im trying that now but the problem is django is causing issues when iterating over a dictionary i think because its a post dictionary 

Exception Value:
  coercing to Unicode: need string or buffer, dict found
Exception Location: /home/grant/workspace/Django Projects/trunk/holon/portal/views.py in portal, line 171


insert_data
  <QueryDict: {u'vm_id_posted': [u'27381'], u'vm_group_name_posted': [u'Unassigned'], u'vm_name_posted': [u'HyTrust-ESXi01'], u'assign_customer': [u'61'], u'vm_datacenter_id_posted': [u'2'], u'vm_edit': [u'edit'], u'vm_mor_posted': [u'vm-8026'], u'save': [u'save'], u'INGVMWESXI': [u'INGVMWESXI'], u'insert': [u'yes'], u'customer_id': [u'1'], u'csrfmiddlewaretoken': [u'4e8g52f3Hj4GmzWpQlfL8YvdJrETNZ8k'], u'vm_group_id_posted': [u'1'], u'vm_id': [u'27390'], u'vm_vcd_managed_posted': [u'Y'], u'vm_display_name_posted': [u'HyTrust-ESXi01']}>


post_value
u'vm_id_posted'

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b4eb8f2f-e98a-437d-8656-1714f958af12%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL2Rd%3DK_tbbfg0YB38tB_A49XE4rcGxkHUNx4azMzcb-vpKY0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment