ListView and Deleteview
Hello everybody, I'm working in a website using django. I would like that users could select and delete data introduced for them. I've found some information on the web and it seems that the ListView and DeleteView is what I need. However, when I try to do a ListView, it doesn't work and I don't know why. Here my code: *models.py:* class Pozo(models.Model): # gid_pozo = models.IntegerField(primary_key=True) # gid_colector = models.ForeignKey(Colector) codpozo = models.CharField(max_length=20) coorx = models.DecimalField(max_digits=13, decimal_places=5) coory = models.DecimalField(max_digits=13, decimal_places=5) tipo = models.CharField(max_length=20) cotatrapa = models.DecimalField(max_digits=6, decimal_places=2, default=None, blank=True, null=True) profundidad = models.DecimalField(max_digits=6, decimal_places=2, default=None, blank=True, null=True) cotafondo = models.DecimalField(max_digits=6, decimal_places=2, default=None, blank=True, null=True) material = models.CharField(max_length=20) materialpates = models.CharField(max_length=20) diametro = models.DecimalField(max_digits=20, decimal_places=2, default=None, blank=True, null=True) largotrapa = models.DecimalField(max_digits=20, decimal_places=2, default=None, blank=True, null=True) seccionmayor = models.DecimalField(max_digits=5, decimal_places=0, default=None, blank=True, null=True) seccionmenor = models.DecimalField(max_digits=5, decimal_places=0, default=None, blank=True, null=True) numacometidas = models.DecimalField(max_digits=2, decimal_places=0, default=None, blank=True, null=True) origen = models.CharField(max_length=20) observaciones = models.CharField(max_length=255) geom = models.PointField(srid=25830) objects = models.GeoManager() *views.py:* def PozoList(ListView): model = Pozo template_name = 'cuencas/edicioncuenca.html' *template:* {% for pozo in object_list %} {{ pozo.codpozo }} {% endfor %} And the result is a field without options. Does anybody know what I'm doing wrong? Thank you very much! -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9492aae7-31bf-4283-9399-5c50f04dfcfa%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: ListView and Deleteview
Soory, it's a class, but it doesn't work properly neither. Do I have to introduce anything in urls.py? I haven't put anything because I want the listview in a url already created. El lunes, 2 de febrero de 2015, 13:29:53 (UTC+1), elcaiaimar escribió: > > Hello everybody, > > I'm working in a website using django. I would like that users could > select and delete data introduced for them. I've found some information on > the web and it seems that the ListView and DeleteView is what I need. > However, when I try to do a ListView, it doesn't work and I don't know why. > > Here my code: > > *models.py:* > > class Pozo(models.Model): > # gid_pozo = models.IntegerField(primary_key=True) > # gid_colector = models.ForeignKey(Colector) > codpozo = models.CharField(max_length=20) > coorx = models.DecimalField(max_digits=13, decimal_places=5) > coory = models.DecimalField(max_digits=13, decimal_places=5) > tipo = models.CharField(max_length=20) > cotatrapa = models.DecimalField(max_digits=6, decimal_places=2, > default=None, blank=True, null=True) > profundidad = models.DecimalField(max_digits=6, decimal_places=2, > default=None, blank=True, null=True) > cotafondo = models.DecimalField(max_digits=6, decimal_places=2, > default=None, blank=True, null=True) > material = models.CharField(max_length=20) > materialpates = models.CharField(max_length=20) > diametro = models.DecimalField(max_digits=20, decimal_places=2, > default=None, blank=True, null=True) > largotrapa = models.DecimalField(max_digits=20, decimal_places=2, > default=None, blank=True, null=True) > seccionmayor = models.DecimalField(max_digits=5, decimal_places=0, > default=None, blank=True, null=True) > seccionmenor = models.DecimalField(max_digits=5, decimal_places=0, > default=None, blank=True, null=True) > numacometidas = models.DecimalField(max_digits=2, decimal_places=0, > default=None, blank=True, null=True) > origen = models.CharField(max_length=20) > observaciones = models.CharField(max_length=255) > geom = models.PointField(srid=25830) > objects = models.GeoManager() > > *views.py:* > > def PozoList(ListView): > model = Pozo > template_name = 'cuencas/edicioncuenca.html' > > *template:* > > > {% for pozo in object_list %} > {{ pozo.codpozo }} > {% endfor %} > > > And the result is a field without options. Does anybody know what I'm > doing wrong? > Thank you very much! > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f3e6ef57-5a4f-4af5-a981-b364424bbc4d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
JsonResponse and ajax function
Hello! I've written a code to delete db registers and I want to call an ajax function when the delete is done. At the moment, when I click my delete button I only receive a message: {"status":"True","product_id":p.id} or {"status":"False"} and this should be sent to the ajax function and I shoud have an alert saying to me: product has been removed. I don't know why, probably there is something wrong in the relation of my JsonResponse and ajax function. I put my code below. Does anybody know how can I fix this? Thank you very much! *template*: {% csrf_token %} Cerrar Eliminar *views.py:* if request.method=="POST": if "product_id" in request.POST: try: id_producto = request.POST['product_id'] p = Pozo.objects.get(pk=id_producto) mensaje = {"status":"True","product_id":p.id} p.delete() # Elinamos objeto de la base de datos return JsonResponse(mensaje) except: mensaje = {"status":"False"} return JsonResponse(mensaje) *Ajax.js:*/ Autor: @jqcaper // Configuraciones Generales var nombre_tabla = "#tabla_productos"; // id var nombre_boton_eliminar = ".delete"; // Clase var nombre_formulario_modal = "#frmEliminar"; //id var nombre_ventana_modal = "#myModal"; // id // Fin de configuraciones $(document).on('ready',function(){ $(nombre_boton_eliminar).on('click',function(e){ e.preventDefault(); var Pid = $(this).attr('id'); var name = $(this).data('name'); $('#modal_idProducto').val(Pid); $('#modal_name').text(name); }); var options = { success:function(response) { if(response.status=="True"){ alert("Eliminado!"); var idProd = response.product_id; var elementos= $(nombre_tabla+' >tbody >tr').length; if(elementos==1){ location.reload(); }else{ $('#tr'+idProd).remove(); $(nombre_ventana_modal).modal('hide'); } }else{ alert("Hubo un error al eliminar!"); $(nombre_ventana_modal).modal('hide'); }; } }; $(nombre_formulario_modal).ajaxForm(options); }); -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c295d8a5-79bb-427b-be04-86dcb0d698e7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
JsonResponse and Ajax function.
Hello! I've written a code to delete db registers and I want to call an ajax function when the delete is done. At the moment, when I click my delete button I only receive a message: {"status":"True","product_id":p.id} or {"status":"False"} and this should be sent to the ajax function and I shoud have an alert saying to me: product has been removed. I don't know why, probably there is something wrong in the relation of my JsonResponse and ajax function. I put my code below. Does anybody know how can I fix this? Thank you very much! *template*: {% csrf_token %} Cerrar Eliminar *views.py:* if request.method=="POST": if "product_id" in request.POST: try: id_producto = request.POST['product_id'] p = Pozo.objects.get(pk=id_producto) mensaje = {"status":"True","product_id":p.id} p.delete() # Elinamos objeto de la base de datos return JsonResponse(mensaje) except: mensaje = {"status":"False"} return JsonResponse(mensaje) *Ajax.js:*// Autor: @jqcaper // Configuraciones Generales var nombre_tabla = "#tabla_productos"; // id var nombre_boton_eliminar = ".delete"; // Clase var nombre_formulario_modal = "#frmEliminar"; //id var nombre_ventana_modal = "#myModal"; // id // Fin de configuraciones $(document).on('ready',function(){ $(nombre_boton_eliminar).on('click',function(e){ e.preventDefault(); var Pid = $(this).attr('id'); var name = $(this).data('name'); $('#modal_idProducto').val(Pid); $('#modal_name').text(name); }); var options = { success:function(response) { if(response.status=="True"){ alert("Eliminado!"); var idProd = response.product_id; var elementos= $(nombre_tabla+' >tbody >tr').length; if(elementos==1){ location.reload(); }else{ $('#tr'+idProd).remove(); $(nombre_ventana_modal).modal('hide'); } }else{ alert("Hubo un error al eliminar!"); $(nombre_ventana_modal).modal('hide'); }; } }; $(nombre_formulario_modal).ajaxForm(options); }); -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/66cfb1b0-e5e0-4393-8e87-2cde5a9f77c4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
JSON Response
Hello, I was wondering how I can send a response JSON in a good way, because I have the next code: if "product_id" in request.POST: try: id_producto = request.POST['product_id'] p = Pozo.objects.get(pk=id_producto) mensaje = {"status":"True","product_id":p.id} p.delete() # Elinamos objeto de la base de datos return JsonResponse(mensaje) except: mensaje = {"status":"False"} return JsonResponse(mensaje) And my JS function doesn't work with this code: var options = { success:function(response) { if(response.status=="True"){ alert("Eliminado!"); var idProd = response.product_id; var elementos= $(nombre_tabla+' >tbody >tr').length; if(elementos==1){ location.reload(); }else{ $('#tr'+idProd).remove(); $(nombre_ventana_modal).modal('hide'); } }else{ alert("Hubo un error al eliminar!"); $(nombre_ventana_modal).modal('hide'); }; } }; $(nombre_formulario_modal).ajaxForm(options); }); And I don't know what I can do. Does anyone have any idea? -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2cfc6283-ee2f-4280-b086-2dc1595855c8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: JSON Response
I mean in a correct form. My code doesn't work. It seems like the JS code doesn't receive the jsonresponse. I get a page with {"status":"True","product_id":p.id} But this should be read for the JS code, and if it's True show an alert saying Remove it! Is there anything wrong in my code? El jueves, 19 de febrero de 2015, 21:49:59 (UTC+1), Vijay Khemlani escribió: > > What do you mean with "in a good way"? Does your code work? > > On Thu, Feb 19, 2015 at 4:14 PM, elcaiaimar > wrote: > >> Hello, >> >> I was wondering how I can send a response JSON in a good way, because I >> have the next code: >> >> if "product_id" in request.POST: >> try: >> id_producto = request.POST['product_id'] >> p = Pozo.objects.get(pk=id_producto) >> mensaje = {"status":"True","product_id":p.id} >> p.delete() # Elinamos objeto de la base de datos >> return JsonResponse(mensaje) >> except: >> mensaje = {"status":"False"} >> return JsonResponse(mensaje) >> >> And my JS function doesn't work with this code: >> >>var options = { >> success:function(response) >> { >> if(response.status=="True"){ >> alert("Eliminado!"); >> var idProd = response.product_id; >> var elementos= $(nombre_tabla+' >tbody >tr').length; >> if(elementos==1){ >> location.reload(); >> }else{ >> $('#tr'+idProd).remove(); >> $(nombre_ventana_modal).modal('hide'); >> } >> }else{ >> alert("Hubo un error al eliminar!"); >> $(nombre_ventana_modal).modal('hide'); >> }; >> } >> }; >> $(nombre_formulario_modal).ajaxForm(options); >> }); >> >> And I don't know what I can do. Does anyone have any idea? >> >> -- >> 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...@googlegroups.com . >> To post to this group, send email to django...@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/2cfc6283-ee2f-4280-b086-2dc1595855c8%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/2cfc6283-ee2f-4280-b086-2dc1595855c8%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> 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+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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e57dc93c-07a1-4d86-9155-0f0a76bde9fe%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: JSON Response
Please, have a look at this tutorial: https://www.youtube.com/watch?v=Pxn5L1qJTAw Sorry, It's in spanish, but it's what I'm doing. I've tried to put the same code but it doesn't work because he uses an older version of django. If you don't want to see all the video, you can see the minute 12:16. He clicks on the remove button and then, an alert appears! My django version is 1.7 I hope this helps! And Thank you for your answers! El jueves, 19 de febrero de 2015, 20:14:32 (UTC+1), elcaiaimar escribió: > > Hello, > > I was wondering how I can send a response JSON in a good way, because I > have the next code: > > if "product_id" in request.POST: > try: > id_producto = request.POST['product_id'] > p = Pozo.objects.get(pk=id_producto) > mensaje = {"status":"True","product_id":p.id} > p.delete() # Elinamos objeto de la base de datos > return JsonResponse(mensaje) > except: > mensaje = {"status":"False"} > return JsonResponse(mensaje) > > And my JS function doesn't work with this code: > >var options = { > success:function(response) > { > if(response.status=="True"){ > alert("Eliminado!"); > var idProd = response.product_id; > var elementos= $(nombre_tabla+' >tbody >tr').length; > if(elementos==1){ > location.reload(); > }else{ > $('#tr'+idProd).remove(); > $(nombre_ventana_modal).modal('hide'); > } > }else{ > alert("Hubo un error al eliminar!"); > $(nombre_ventana_modal).modal('hide'); > }; > } > }; > $(nombre_formulario_modal).ajaxForm(options); > }); > > And I don't know what I can do. Does anyone have any idea? > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7598022d-83b0-4c49-b8e1-a86b169fd336%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: JSON Response
I solved it! Sorry, at last I had a bad called to jquery library in my base.html. I had to check all my project Thank you for your answers, you have helped me a lot! El viernes, 20 de febrero de 2015, 21:01:46 (UTC+1), elcaiaimar escribió: > > Please, have a look at this tutorial: > https://www.youtube.com/watch?v=Pxn5L1qJTAw > Sorry, It's in spanish, but it's what I'm doing. I've tried to put the > same code but it doesn't work because he uses an older version of django. > If you don't want to see all the video, you can see the minute 12:16. > He clicks on the remove button and then, an alert appears! > My django version is 1.7 > > I hope this helps! > > And Thank you for your answers! > > El jueves, 19 de febrero de 2015, 20:14:32 (UTC+1), elcaiaimar escribió: >> >> Hello, >> >> I was wondering how I can send a response JSON in a good way, because I >> have the next code: >> >> if "product_id" in request.POST: >> try: >> id_producto = request.POST['product_id'] >> p = Pozo.objects.get(pk=id_producto) >> mensaje = {"status":"True","product_id":p.id} >> p.delete() # Elinamos objeto de la base de datos >> return JsonResponse(mensaje) >> except: >> mensaje = {"status":"False"} >> return JsonResponse(mensaje) >> >> And my JS function doesn't work with this code: >> >>var options = { >> success:function(response) >> { >> if(response.status=="True"){ >> alert("Eliminado!"); >> var idProd = response.product_id; >> var elementos= $(nombre_tabla+' >tbody >tr').length; >> if(elementos==1){ >> location.reload(); >> }else{ >> $('#tr'+idProd).remove(); >> $(nombre_ventana_modal).modal('hide'); >> } >> }else{ >> alert("Hubo un error al eliminar!"); >> $(nombre_ventana_modal).modal('hide'); >> }; >> } >> }; >> $(nombre_formulario_modal).ajaxForm(options); >> }); >> >> And I don't know what I can do. Does anyone have any idea? >> > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1cad0560-be64-45f5-9091-f2c2f07e07c2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Read a csv file and save data in postgresql
Hello, I have a website and I need that users can introduce a csv file and save their data in a postgresql database. I can introduce a file and save it in media_dir and in the database (only the url). But what I want is save each row as a register in a table. I've searched some examples but I haven't found exactly this. Is it possible to do? Has anyone done this before? I put my code to save the file in a database and in media below: *views* if 'formularioarchivo' in request.POST: formularioarchivo = UploadForm(request.POST, request.FILES) if formularioarchivo.is_valid(): newdoc = Archivo(docfile = request.FILES['docfile']) newdoc.save(formularioarchivo) return HttpResponseRedirect('/edicioncuenca/') else: formularioarchivo = UploadForm() *models* class Archivo(models.Model): # gid_archivo = models.IntegerField(primary_key=True) docfile = models.FileField(upload_to='%Y/%m/%d') *forms* class UploadForm(forms.Form): docfile = forms.FileField( label='Selecciona un archivo' ) *template* {% csrf_token %} {{ formularioarchivo.as_p }} -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3b4bb9f0-2539-4486-b47a-c782ff350e99%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
render_to_response and HttpResponseRedirect
Hello! I'm having problems in a form. I want to send some values with it to 'obras/edicionobra.html' but I also want to redirect to the page "/edicionobra/". In the code below I send the values and I go to edicionobra.html, however, the URL is /nuevacuenca/ and that's wrong. I've tried to put HttpResponseRedirect("/edicionobra/") at the end of the form, but then I don't send the values How can I solve my problem? def NuevaCuenca(request): if not request.user.is_authenticated(): return HttpResponseRedirect('/') idobra=request.POST['obra'] lobras = Obra.objects.filter(id=idobra) obra=lobras[0] cuencas = CuencasObra(request) if "nuevacuenca" in request.POST: formulario = CuencasForm(request.POST) if formulario.is_valid(): titulo = 'Formulario de cuenca' dc=request.POST['descripcion_cuenca'] idobra=request.POST['obra'] cuenca=Cuenca(gid_obra_id=idobra, descripcion_cuenca=dc) cuenca.save() return render_to_response('obras/edicionobra.html', {'idobra': idobra, 'obra':obra, 'cuencas':cuencas}, context_instance=RequestContext( request)) else: formulario = CuencasForm() return render_to_response('cuencas/nuevacuenca.html',{'formulario': formulario, 'idobra':idobra, 'obra':obra}, context_instance=RequestContext( request)) -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9f5a1420-043b-4686-bd1f-3eb2eee383b6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: render_to_response and HttpResponseRedirect
Finally, I've changed my way to send parameters, it's much better send them by url. El miércoles, 11 de marzo de 2015, 11:21:34 (UTC+1), elcaiaimar escribió: > > Hello! > > I'm having problems in a form. I want to send some values with it to > 'obras/edicionobra.html' but I also want to redirect to the page > "/edicionobra/". In the code below I send the values and I go to > edicionobra.html, however, the URL is /nuevacuenca/ and that's wrong. > > I've tried to put HttpResponseRedirect("/edicionobra/") at the end of the > form, but then I don't send the values > > How can I solve my problem? > def NuevaCuenca(request): > if not request.user.is_authenticated(): > return HttpResponseRedirect('/') > > idobra=request.POST['obra'] > lobras = Obra.objects.filter(id=idobra) > obra=lobras[0] > cuencas = CuencasObra(request) > if "nuevacuenca" in request.POST: > formulario = CuencasForm(request.POST) > if formulario.is_valid(): > titulo = 'Formulario de cuenca' > > dc=request.POST['descripcion_cuenca'] > idobra=request.POST['obra'] > > cuenca=Cuenca(gid_obra_id=idobra, descripcion_cuenca=dc) > > cuenca.save() > > return render_to_response('obras/edicionobra.html', {'idobra': > idobra, 'obra':obra, 'cuencas':cuencas}, context_instance=RequestContext( > request)) > else: > formulario = CuencasForm() > return render_to_response('cuencas/nuevacuenca.html',{'formulario': > formulario, 'idobra':idobra, 'obra':obra}, context_instance=RequestContext > (request)) > > > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dad86c29-22f3-42cc-9152-cbc78299c485%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Uncaught TypeError: Cannot read property 'value' of null
Hello I wonder if somebody knows how to solve the next: I want to send a value from the template to a script and it seems it works but I get an error: Uncaught TypeError: Cannot read property 'value' of null Below it is my code: *Template:* {{ obra.id }} is an object sended from views.py *Javascript:* var idobra = document.getElementById("idobra").value; console.log(idobra); And I don't know what I'm doing wrong. I would like to know if there is another way to send objects directly from django to javascript or if I'm doing well like that, but solving the problem. Thank you very much! -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/81b65371-ce65-40e2-94ff-a876a24f6a86%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
null value in column "geom" violates not-null constraint
Hello everybody, I'm working with django and geodjango and now I have a problem with the geometry. I want that users can introduce coordinates in a form and then, these are saved in a database (postgis). Now, I can save X and Y coordinates, but the geom field doesn't work and I don't know why. In my models.py I have create the next class: from django.contrib.gis.db import models class Pozo(models.Model): # gid_pozo = models.IntegerField(primary_key=True) # gid_colector = models.ForeignKey(Colector) coorx = models.IntegerField() coory = models.IntegerField() geom = models.PointField() objects = models.GeoManager() When I introduce coordinates, I get this error: null value in column "geom" violates not-null constraint DETAIL: Failing row contains (7, -1, 1, null). 7 = id, -1, 1 =coordinates, null=geom What I can solve this trouble? Thank you very much! -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ec67c578-f073-4845-822f-5684d0174db7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
DecimalField returns 'This value must be a decimal number' when blank
Hello everybody, I've a problem with DecimalField at Forms. I've a long form in my template and I want to left some fields in blank. I've declared these fields with *required=False*, but when I submit the form I receive this error: '*This value must be a decimal number*'. I've tried to declare *blank=True, null=True* in respective fields in models.py and make a syncdb but it continues without works Does somebody know how could I solve this problem? Thank you very much! -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/95da2ed1-e9ce-43c5-9e53-3d17cab471d5%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: DecimalField returns 'This value must be a decimal number' when blank
Hello! I've tried to do a makemigrations and a migrate but It returns "No changes detected" and "No migrations to apply". Sorry Vijay Khemlani, I forgot it, you have my code here: forms.py: class PozosForm(forms.Form): codpozo = forms.CharField(max_length=20) coorx = forms.DecimalField(max_digits=13, decimal_places=5) coory = forms.DecimalField(max_digits=13, decimal_places=5) tipo = forms.CharField(max_length=20, required=False) cotatrapa = forms.DecimalField(max_digits=6, decimal_places=2, required=False) profundidad = forms.DecimalField(max_digits=6, decimal_places=2, required=False) cotafondo = forms.DecimalField(max_digits=6, decimal_places=2, required=False) material = forms.ChoiceField(choices=MATERIAL_POZOS, required=False) materialpates = forms.ChoiceField(choices=MATERIAL_PATES, required=False) diametro = forms.DecimalField(max_digits=20, decimal_places=2, required=False) largotrapa = forms.DecimalField(max_digits=20, decimal_places=2, required=False) seccionmayor = forms.DecimalField(max_digits=5, decimal_places=0, required=False) seccionmenor = forms.DecimalField(max_digits=5, decimal_places=0, required=False) numacometidas = forms.DecimalField(max_digits=2, decimal_places=0, required=False) models.py: class Pozo(models.Model): # gid_pozo = models.IntegerField(primary_key=True) # gid_colector = models.ForeignKey(Colector) codpozo = models.CharField(max_length=20) coorx = models.DecimalField(max_digits=13, decimal_places=5) coory = models.DecimalField(max_digits=13, decimal_places=5) tipo = models.CharField(max_length=20) cotatrapa = models.DecimalField(max_digits=6, decimal_places=2, blank=True, null=True) profundidad = models.DecimalField(max_digits=6, decimal_places=2, blank=True, null=True) cotafondo = models.DecimalField(max_digits=6, decimal_places=2, blank=True, null=True) material = models.CharField(max_length=20) materialpates = models.CharField(max_length=20) diametro = models.DecimalField(max_digits=20, decimal_places=2, blank=True, null=True) largotrapa = models.DecimalField(max_digits=20, decimal_places=2, blank=True, null=True) seccionmayor = models.DecimalField(max_digits=5, decimal_places=0, blank=True, null=True) seccionmenor = models.DecimalField(max_digits=5, decimal_places=0, blank=True, null=True) numacometidas = models.DecimalField(max_digits=2, decimal_places=0, blank=True, null=True) I think everything is ok, but if you find errors, please tell me. If not, I will try to use south. Thank you very much! El domingo, 16 de noviembre de 2014 18:51:43 UTC+1, elcaiaimar escribió: > > Hello everybody, I've a problem with DecimalField at Forms. I've a long > form in my template and I want to left some fields in blank. I've declared > these fields with > *required=False*, but when I submit the form I receive this error: '*This > value must be a decimal number*'. > > I've tried to declare *blank=True, null=True* in respective fields in > models.py and make a syncdb but it continues without works > > Does somebody know how could I solve this problem? > > Thank you very much! > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cc92e84d-d5da-4635-a365-a823ed83ecce%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: DecimalField returns 'This value must be a decimal number' when blank
I' ve seen that south is for older django versions than 1.7, I continue having the same problem, I wonder if the issue will be in my views, when I save all the information, please, have a look to my code: if 'formulariopozo' in request.POST: formulario = PozosForm(request.POST) if formulario.is_valid(): titulo = 'Formulario de pozos' codpozo=request.POST['codpozo'] x=request.POST['coorx'] y=request.POST['coory'] tipo=request.POST['tipo'] cotatrapa=request.POST['cotatrapa'] profundidad=request.POST['profundidad'] cotafondo=request.POST['cotafondo'] material=request.POST['material'] materialpates=request.POST['materialpates'] diametro=request.POST['diametro'] largotrapa=request.POST['largotrapa'] seccionmayor=request.POST['seccionmayor'] seccionmenor=request.POST['seccionmenor'] numacometidas=request.POST['numacometidas'] origen=request.POST['origen'] observaciones=request.POST['observaciones'] pnt=Point(float(x),float(y)) xy=Pozo(codpozo=codpozo, coorx=x, coory=y, tipo=tipo, cotatrapa=cotatrapa, profundidad=profundidad, cotafondo=cotafondo, material=material, materialpates=materialpates, diametro=diametro, largotrapa=largotrapa, seccionmayor=seccionmayor, seccionmenor=seccionmenor, numacometidas=numacometidas, origen=origen, observaciones=observaciones, geom=pnt) xy.save() I've tried to put default=None or default=Decimal('0.00') in my models.py but it continues without working. I don't know what can I do Thank you very much El domingo, 16 de noviembre de 2014 18:51:43 UTC+1, elcaiaimar escribió: > > Hello everybody, I've a problem with DecimalField at Forms. I've a long > form in my template and I want to left some fields in blank. I've declared > these fields with > *required=False*, but when I submit the form I receive this error: '*This > value must be a decimal number*'. > > I've tried to declare *blank=True, null=True* in respective fields in > models.py and make a syncdb but it continues without works > > Does somebody know how could I solve this problem? > > Thank you very much! > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/41cbd070-ad71-4eea-a7d4-23fbd21190c0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: DecimalField returns 'This value must be a decimal number' when blank
Hi Collin I'm using postgresql db, I' ve attached my views, forms and models. I' ve thought to do the ModelForm when I solve this problem, thanks for your advice! Thank you very much! El domingo, 16 de noviembre de 2014 18:51:43 UTC+1, elcaiaimar escribió: > > Hello everybody, I've a problem with DecimalField at Forms. I've a long > form in my template and I want to left some fields in blank. I've declared > these fields with > *required=False*, but when I submit the form I receive this error: '*This > value must be a decimal number*'. > > I've tried to declare *blank=True, null=True* in respective fields in > models.py and make a syncdb but it continues without works > > Does somebody know how could I solve this problem? > > Thank you very much! > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/df6fd584-e398-4d48-bbcd-23c96518f8ee%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. # _*_ encoging: utf-8 _*_ from django import forms class CuencasForm(forms.Form): descripcion_cuenca = forms.CharField() class ColectoresForm(forms.Form): referencia = forms.CharField() TIPO_POZO = ( ('', ''), ('INDETERMINADO', 'Indeterminado'), ('CONTINUACION', 'Continuacion'), ('CONEXION SIN POZO', 'Conexion sin pozo'), ('ENTRONQUE', 'Entronque'), ('CABECERA', 'Cabecera'), ('PARTIDOR', 'Partidor'), ('TRANSICION', 'Transicion'), ('VERTIDO', 'Vertido'), ('VIRTUAL', 'Virtual'), ('JPL', 'JPL'), ('PRESA HINCHABLE', 'Presa hinchable'), ('AZUD', 'Azud'), ) MATERIAL_POZOS = ( ('', ''), ('INDETERMINADO', 'Indeterminado'), ('HORMIGON', 'Hormigon'), ('MIXTO', 'Mixto'), ('OBRA DE FABRICA', 'Obra de fabrica'), ('PIEDRA', 'Piedra'), ('PREFABRICADO', 'Prefabricado'), ) MATERIAL_PATES = ( ('', ''), ('INDETERMINADO', 'Indeterminado'), ('METALICOS', 'Metalicos'), ('NO EXISTEN', 'No existen'), ('POLIPROPILENO', 'Polipropileno'), ) class PozosForm(forms.Form): codpozo = forms.CharField(max_length=20) coorx = forms.DecimalField(max_digits=13, decimal_places=5) coory = forms.DecimalField(max_digits=13, decimal_places=5) tipo = forms.ChoiceField(choices=TIPO_POZO, required=False) cotatrapa = forms.DecimalField(max_digits=6, decimal_places=2, required=False) profundidad = forms.DecimalField(max_digits=6, decimal_places=2, required=False) cotafondo = forms.DecimalField(max_digits=6, decimal_places=2, required=False) material = forms.ChoiceField(choices=MATERIAL_POZOS, required=False) materialpates = forms.ChoiceField(choices=MATERIAL_PATES, required=False) diametro = forms.DecimalField(max_digits=20, decimal_places=2, required=False) largotrapa = forms.DecimalField(max_digits=20, decimal_places=2, required=False) seccionmayor = forms.DecimalField(max_digits=5, decimal_places=0, required=False) seccionmenor = forms.DecimalField(max_digits=5, decimal_places=0, required=False) numacometidas = forms.DecimalField(max_digits=2, decimal_places=0, required=False) origen = forms.CharField(max_length=20, required=False) observaciones = forms.CharField(widget=forms.Textarea(), required=False) TIPO_IMBORNAL = ( ('', ''), ('INDETERMINADO', 'Indeterminado'), ('BUZON', 'Buzon'), ('CUADRADO', 'Cuadrado'), ('HEXAGONAL', 'Hexagonal'), ('IMBORNAL NO ESTANDAR', 'Imbornal no estandar'), ('RECTANGULAR', 'Rectangular'), ('RECTANGULAR DOBLE', 'Rectangular doble'), ('RECTANGULAR PEQUENO', 'Rectangular pequeno'), ('REJILLA NO ESTANDAR', 'Rejilla no estandar'), ('SEMICIRCULAR', 'Semicircular'), ) class ImbornalesForm(forms.Form): codimbornal = forms.CharField(max_length=20) coorx = forms.DecimalField(max_digits=13, decimal_places=5) coory = forms.DecimalField(max_digit
Re: DecimalField returns 'This value must be a decimal number' when blank
It works! You are great Collin! Thank you very much! El domingo, 16 de noviembre de 2014 18:51:43 UTC+1, elcaiaimar escribió: > > Hello everybody, I've a problem with DecimalField at Forms. I've a long > form in my template and I want to left some fields in blank. I've declared > these fields with > *required=False*, but when I submit the form I receive this error: '*This > value must be a decimal number*'. > > I've tried to declare *blank=True, null=True* in respective fields in > models.py and make a syncdb but it continues without works > > Does somebody know how could I solve this problem? > > Thank you very much! > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fb25d052-5d45-4e17-8cbf-e16dbe272988%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
reading CSV file with non ASCII characters
Hello, I have a CSV File and I want read it. The problem is that it has non ASCII characters such as 'Ñ' and accents and I need that they are recognised to save the CSV content in a DB. To simplify, I've summed up my code in django to the next: import csv reader = csv.DictReader(open("file.csv", "rb")) for row in reader: title=row['title'] country=row['country'] print title print country This code returns, for example: Espa�a or Mediterr�neo and I want to get España or Mediterráneo. Thank you very much! -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/54c6c685-f4dd-4233-9a30-22424c986a43%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: reading CSV file with non ASCII characters
Thank you for your quick answers. I've tried what you recommended me. My code is like that now: import unicodecsv as csv csvfile=open("mediosdigitales.csv") reader = csv.reader(csvfile, encoding='utf-8', delimiter=',') for row in reader: titulo=row['titulo'] pais=row['pais'] print titulo print pais However, when I compile it I get this error: *list indices must be integers, not str* How could I solve this problem? Thank you again El sábado, 6 de febrero de 2016, 3:14:01 (UTC+1), elcaiaimar escribió: > > Hello, > > I have a CSV File and I want read it. The problem is that it has non ASCII > characters such as 'Ñ' and accents and I need that they are recognised to > save the CSV content in a DB. > > To simplify, I've summed up my code in django to the next: > > import csv > > reader = csv.DictReader(open("file.csv", "rb")) > for row in reader: > title=row['title'] > country=row['country'] > print title > print country > > This code returns, for example: Espa�a or Mediterr�neo and I want to get > España or Mediterráneo. > > Thank you very much! > > -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fa59d6cd-588e-4754-aa97-a8ca9a5f6e5e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Send an object parameter from views.py to forms.py
Hello, I have a problem because I don't know how could I send one specific parameter. I've sent other parameters sometimes in others apps but this time is more difficult. Below it's my code. I want to send '*p*', which is an object. The problem is that I can't send it in *else *because I've defined *p *outside (*if*). So when I tried to send it, *p *is not defined. I can't define it outside because I need *id_medioedit*, which is an id obtained from template in *medioedit_id* form. Anyone who knows how to solve this? Thank you in advance Views.py if 'medioedit_id' in request.POST: formularioeditarmedios = EditMediosForm(request.POST) try: id_medioedit = request.POST['medioedit_id'] p = Medios.objects.get(pk=id_medioedit) mensaje = {"status":"True","medioedit_id":p.id} if formularioeditarmedios.is_valid(): ... else: formularioeditarmedios = EditMediosForm(p=p) Forms.py class EditMediosForm(forms.Form): #initial='somevalue' titulo = forms.CharField(max_length=140, widget=forms.TextInput(attrs={ 'style': 'width:140px'})) def __init__(self,p,*args,**kwargs): p = kwargs.pop("p", None) super(EditMediosForm, self).__init__(*args,**kwargs) self.fields['titulo'].initial = p.titulo -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e4c77318-156a-40da-9761-9c03f382af77%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
datetime.date is not json serializable
Hello, I'm having a problem when I try to convert a python dictionary into a json dictionary (*json.dumps(results, ensure_ascii=False)*). Everything is ok, but when there is a date as a valure of the dictionary I get this error: datetime.date is not json serializable. I don't know how to solve this. Here my code: mysqldb = get_mysql_db() cursor = mysqldb.cursor()# SQL query cursor.execute("SELECT titulo, url from content_medios") # getting the name of columns columns = [column[0] for column in cursor.description] # creating the dictionary results = [] for row in cursor.fetchall(): results.append(dict(zip(columns, row))) # converting from py to json jsonarray = json.dumps(results, ensure_ascii=False) return jsonarray mysqldb.close() Thank you in advance -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/78d4f809-2a00-4bfb-8014-5cdeff4cf8e4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Don't save anything if error on save method
Hello, I' ve an application where I upload a CSV file and save all its rows in a database. This is ok, but, at the moment, when I upload the file and it exists some error on it, it saves all rows until the wrong row. What I want to achieve is that if there is an error when I save, don't save anything. Is there any way to do that? if formularioarchivomedios.is_valid(): reader = csv.DictReader(request.FILES['docfile'], delimiter=',') for row in reader: try: titulo=row['titulo'] url=row['url'] my_file = Medios(titulo=titulo, url=url) my_file.save() Thank you in advance! -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/908406c1-3f06-4889-953e-544a7a43afea%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.