Re: Dictionary key-value pair

2008-08-28 Thread David Zhou


On Aug 28, 2008, at 1:18 PM, saeb wrote:

> No, it is not just those fields, there are about 20 key-value items. I
> have a Database with about 40 tables. and I am essentially trying to
> render a snapshot of about 15 important table which had foreign key
> relationship with other tables.  Following will give you an idea of
> what I am trying to do. Thanks

Since it looks like you're basically using the dictionary like a list  
of tuples, why not make it a list of tuples?  It should preserve  
ordering too, that way.



---
David Zhou
[EMAIL PROTECTED]




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Dictionary key-value pair

2008-08-28 Thread saeb


No, it is not just those fields, there are about 20 key-value items. I
have a Database with about 40 tables. and I am essentially trying to
render a snapshot of about 15 important table which had foreign key
relationship with other tables.  Following will give you an idea of
what I am trying to do. Thanks




template ---




 User details 

{% for i in user_details.items %}
 
{{i.0}} {{i.1}}
{% endfor %}




 Order details 

{% for i in order_details.items %}
 
{{i.0}} {{i.1}}
{% endfor %}


:
:
:


---views.py-

   if request.method == 'POST':

user_id = request.POST["user_id"]

user = Users.objects.get(pk=user_id)
user_details['Name'] = user.name
user_details['Login'] = user.login
user_details['Phone No.'] = user.phone_number

user_entity = 
UserEntities.objects.all().filter(owner=user_id)
total_user_profit = sum([obj.profit for obj in 
user_entity])
total_user_loss = sum([obj.loss for obj in user_entity])

trader_acct_details['Total profit'] =  total_user_profit
trader_acct_details['Total loss'] = total_user_profit

orders = Orders.objects.get_todays_orders(user_id)
new_order_count = sum([obj.quantity for obj in
orders.filter(order_state ='N')])
order_details['New Orders'] = new_order_count
 :
 :
 :
  return render_to_response('admin/
Snapshot.html', { 'user_details': user_details, 'user_acct_details':
trader_acct_details,  'order_details': order_details })



On Aug 28, 11:49 am, David Zhou <[EMAIL PROTECTED]> wrote:
> On Aug 28, 2008, at 12:45 PM, saeb wrote:
>
> > order is important for display, I am calculating sum and average on
> > query objects and storing it in dictionary with key/values which are
> > used in a template. So I have a dictionary  something like this :
> > {'name': user1, 'phone': 723872, 'Total Friends': 20, 'Avg Rating' :
> > 3.6}
> > so when I render I would these to appear in order.
>
> Can you post the relevant view and template code?
>
> But if it's just those fields, why not refer to them explicitly? Such
> as:
>
> {{dict_variabe.name}} or {{dict_variable.phone}}
>
> ---
> David Zhou
> [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Dictionary key-value pair

2008-08-28 Thread David Zhou

On Aug 28, 2008, at 12:45 PM, saeb wrote:

> order is important for display, I am calculating sum and average on
> query objects and storing it in dictionary with key/values which are
> used in a template. So I have a dictionary  something like this :
> {'name': user1, 'phone': 723872, 'Total Friends': 20, 'Avg Rating' :
> 3.6}
> so when I render I would these to appear in order.


Can you post the relevant view and template code?

But if it's just those fields, why not refer to them explicitly? Such  
as:

{{dict_variabe.name}} or {{dict_variable.phone}}

---
David Zhou
[EMAIL PROTECTED]




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Dictionary key-value pair

2008-08-28 Thread saeb

order is important for display, I am calculating sum and average on
query objects and storing it in dictionary with key/values which are
used in a template. So I have a dictionary  something like this :
{'name': user1, 'phone': 723872, 'Total Friends': 20, 'Avg Rating' :
3.6}
so when I render I would these to appear in order.

thanks!



On Aug 28, 11:36 am, David Zhou <[EMAIL PROTECTED]> wrote:
> On Aug 28, 2008, at 12:34 PM, saeb wrote:
>
> > I am using a dictionary to render  a template. But my rendered
> > template has the key-value pair  which are out of order. Since
> > dictionary uses a hash table to store it elements, I can't rely on
> > order of  these key-value pairs. Is there any other way to render
> > bunch of key-value items from a view  in a desired order? Thanks for
> > help
>
> What are you trying to do, specifically? If order is important, why
> bother with a key? Why not just store all the values in a list?
>
> ---
> David Zhou
> [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Dictionary key-value pair

2008-08-28 Thread David Zhou

On Aug 28, 2008, at 12:34 PM, saeb wrote:

> I am using a dictionary to render  a template. But my rendered
> template has the key-value pair  which are out of order. Since
> dictionary uses a hash table to store it elements, I can't rely on
> order of  these key-value pairs. Is there any other way to render
> bunch of key-value items from a view  in a desired order? Thanks for
> help

What are you trying to do, specifically? If order is important, why  
bother with a key? Why not just store all the values in a list?

---
David Zhou
[EMAIL PROTECTED]




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Dictionary key-value pair

2008-08-28 Thread saeb


I am using a dictionary to render  a template. But my rendered
template has the key-value pair  which are out of order. Since
dictionary uses a hash table to store it elements, I can't rely on
order of  these key-value pairs. Is there any other way to render
bunch of key-value items from a view  in a desired order? Thanks for
help
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---