[Ncr-Python.in] [ilugd] Django mptt help
Raakesh kumar
kumar3180 at gmail.com
Fri Jun 14 09:05:23 CEST 2013
On Thu, Jun 13, 2013 at 11:12 PM, Gora Mohanty <gora at mimirtech.com> wrote:
> On 13 June 2013 16:49, Raakesh kumar <kumar3180 at gmail.com> wrote:
> >
> > Hi,
> > I am using Django mptt library for tree traversal of mysql data and i am
> > trying to modify the data before i display it in template. Actually in my
> > mysql rows i am inserting few comma separated user ids but i want them to
> > change this part of tree and replace them with the user name.
> > I tried to fetch the tree and loop through it and get corresponding user
> > ids from database and again assigned them to the variable. When i tried
> to
> > print them on console it was working fine but in template it's showing
> the
> > database values. If someone could help me to solve it?
>
> This description makes little sense, at least not to me.
> Please ask a more specific question, and show us
> some code.
>
> Regards,
> Gora
> _______________________________________________
> http://mail.python.org/mailman/listinfo/ncr-python.in
> Mailing list guidelines :
> http://python.org.in/wiki/NcrPython/MailingListGuidelines
>
Ok,
Let me put it in this way:
1 - My table "works" has a column "invities", and this column stores
user_id1,user_id2 type of data. Which means these users are the member for
this particular row data.
2 - And following code is used to view the tree::
def view(request, id):
try:
ideas = Works.objects.filter(tree_id=id).filter(is_deleted=False)
# Following Code is to fetch user details and replace their ids
with name
for i in range(len(ideas)):
invities = ''
members = ideas[i].invities
members = members.split(',')
for member in members:
try:
member_detail = User.objects.get(email = member)
member_name = member_detail.full_name
except User.DoesNotExist:
member_name = member
invities = invities + member_name + ','
ideas[i].invities = invities
except Idea.DoesNotExist:
raise Http404
return render_to_response(
'idea/view.html',
{'nodes': ideas},
context_instance=RequestContext(request)
)
3 - The problem in this code is, when i display idea.invities here, it
works fine but in templates it doesn't show the names but email ids.
4 - Following is the code in template:
{% load mptt_tags %}
{% recursetree nodes %}
Member(s): {{node.invities}}
{% if not node.is_leaf_node %}
<div class="children">
{{ children }}
</div>
{% endif %}
{% endrecursetree %}
Now here i want those name to be displayed.
--
Regards
RAKESH KUMAR
http://raakeshkumar.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ncr-python.in/attachments/20130614/54c24377/attachment.html>
More information about the Ncr-Python.in
mailing list