Re: save data using checkbox click an input

2013-06-02 Thread roopasingh250
Hi,

  I agree that the logic is duplicated, I corrected in views.

  I used that line to render the parent element and below the corresponding 
parent element their respective child element should come to display.That 
logic worked for me.I am updating my new template here,the view code is 
same,now the problem is i am able to save the last parent element's child 
element only.If more than 1 parent element and their child element is 
their,i can save the last parent element's child element data only ,rest of 
them if i check and click save it is not save in database.

updated template is

 {% for type in typeList%}
   {% if type.parent_type_id == None %}
   {{type.title}}
   {% else %}
   {{ type.title 
}} 
   {% endif %}
 {% endfor %}

Can any one help me in achieving.

Thanks

On Saturday, June 1, 2013 5:50:57 PM UTC+5:30, roopas...@gmail.com wrote:
>
> Hi,i am using django developing an app.Problem i am facing is i queried a 
> list of data from one table and save the same data to another table,but the 
> condition is if the user clicks the checkbox and press save.If the checkbox 
> is clicked the value(label) of the checkbox should save in database,this is 
> my requirement in user level(i explained).I tried with the below code ,
>
> views.py
>
> def what(request):
> typeList = Types.objects.filter(user=user, 
> is_active=True,parent_type_id=None)
> list = []
> for type in typeList:
> if not type.parent_type_id:
> list.append(type)
> subtype = Types.objects.filter(parent_type_id=type.id, 
> is_active=True)
> for subtypes in subtype:
> list.append(subtypes)
> if request.method == 'POST':
> ReportType.objects.filter(report=report).delete()
> checked_ones = [unicode(x) for x in subtype if unicode(x) in 
> request.POST.keys()]
> for entry in checked_ones:
> r = ReportType()
> r.report = report 
> r.title = entry
> r.save()
> return redirect('/member/where/')
> checked_ones = [x.title for x in 
> ReportType.objects.filter(report=report)]  
> return render(request, 'incident/what.html',{''typeList':list,'})
>
> template is
> 
>  {% csrf_token %}
> {% for type in typeList%}
>  {% if type.parent_type_id == None %}
>{{type.title}}
>{% else %}
>{{type.title}}
>   {% endif %}
> {% endfor %}
> 
>
> See,i posted all my code to better understand.
>
> Let me tell you the problem i am facing.
>
> 1.I am not able to save the data to database,i believe that my view is 
> ok,might be some problem with template.
>
> Please help me in do this.
>
> Thanks
> 
>

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save data using checkbox click an input

2013-06-01 Thread Artem Zinoviev
How you send your form? Checkbox don`t send your form... Why 
you duplicate logic  in views and template? ( 
for type in typeList:
  if not type.parent_type_id: 
***
&& 
 {% for type in typeList%}
  {% if type.parent_type_id == None %} ).
***

P.S. All this code is incorrect. it can`t work.
This is must be here - 

суббота, 1 июня 2013 г., 15:20:57 UTC+3 пользователь roopas...@gmail.com 
написал:
>
> Hi,i am using django developing an app.Problem i am facing is i queried a 
> list of data from one table and save the same data to another table,but the 
> condition is if the user clicks the checkbox and press save.If the checkbox 
> is clicked the value(label) of the checkbox should save in database,this is 
> my requirement in user level(i explained).I tried with the below code ,
>
> views.py
>
> def what(request):
> typeList = Types.objects.filter(user=user, 
> is_active=True,parent_type_id=None)
> list = []
> for type in typeList:
> if not type.parent_type_id:
> list.append(type)
> subtype = Types.objects.filter(parent_type_id=type.id, 
> is_active=True)
> for subtypes in subtype:
> list.append(subtypes)
> if request.method == 'POST':
> ReportType.objects.filter(report=report).delete()
> checked_ones = [unicode(x) for x in subtype if unicode(x) in 
> request.POST.keys()]
> for entry in checked_ones:
> r = ReportType()
> r.report = report 
> r.title = entry
> r.save()
> return redirect('/member/where/')
> checked_ones = [x.title for x in 
> ReportType.objects.filter(report=report)]  
> return render(request, 'incident/what.html',{''typeList':list,'})
>
> template is
> 
>  {% csrf_token %}
> {% for type in typeList%}
>  {% if type.parent_type_id == None %}
>{{type.title}}
>{% else %}
>{{type.title}}
>   {% endif %}
> {% endfor %}
> 
>
> See,i posted all my code to better understand.
>
> Let me tell you the problem i am facing.
>
> 1.I am not able to save the data to database,i believe that my view is 
> ok,might be some problem with template.
>
> Please help me in do this.
>
> Thanks
> 
>

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




save data using checkbox click an input

2013-06-01 Thread roopasingh250
Hi,i am using django developing an app.Problem i am facing is i queried a 
list of data from one table and save the same data to another table,but the 
condition is if the user clicks the checkbox and press save.If the checkbox 
is clicked the value(label) of the checkbox should save in database,this is 
my requirement in user level(i explained).I tried with the below code ,

views.py

def what(request):
typeList = Types.objects.filter(user=user, 
is_active=True,parent_type_id=None)
list = []
for type in typeList:
if not type.parent_type_id:
list.append(type)
subtype = Types.objects.filter(parent_type_id=type.id, 
is_active=True)
for subtypes in subtype:
list.append(subtypes)
if request.method == 'POST':
ReportType.objects.filter(report=report).delete()
checked_ones = [unicode(x) for x in subtype if unicode(x) in 
request.POST.keys()]
for entry in checked_ones:
r = ReportType()
r.report = report 
r.title = entry
r.save()
return redirect('/member/where/')
checked_ones = [x.title for x in 
ReportType.objects.filter(report=report)]  
return render(request, 'incident/what.html',{''typeList':list,'})

template is

 {% csrf_token %}
{% for type in typeList%}
 {% if type.parent_type_id == None %}
   {{type.title}}
   {% else %}
   {{type.title}}
  {% endif %}
{% endfor %}


See,i posted all my code to better understand.

Let me tell you the problem i am facing.

1.I am not able to save the data to database,i believe that my view is 
ok,might be some problem with template.

Please help me in do this.

Thanks


-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.