ListView and Deleteview

79 views
Skip to first unread message

elcaiaimar

unread,
Feb 2, 2015, 7:29:53 AM2/2/15
to django...@googlegroups.com
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:

<select>
              {% for pozo in object_list %}
                  <option>{{ pozo.codpozo }}</option>
              {% endfor %}
</select>

And the result is a field without options. Does anybody know what I'm doing wrong?
Thank you very much!

Giuseppe Saviano

unread,
Feb 2, 2015, 10:34:08 AM2/2/15
to django...@googlegroups.com
> views.py:
>
> def PozoList(ListView):
> model = Pozo
> template_name = 'cuencas/edicioncuenca.html'
>

Is your view a function or a class?

--
$ gpg --recv-key da5098a7

elcaiaimar

unread,
Feb 2, 2015, 12:40:23 PM2/2/15
to django...@googlegroups.com
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.

Dan Gentry

unread,
Feb 2, 2015, 3:20:58 PM2/2/15
to django...@googlegroups.com
This is a bit of a stumper!

I don't see any big glaring issues.  A couple of housekeeping things:  Is there data in the table? Are you certain that you are using the correct template?

Vijay Khemlani

unread,
Feb 2, 2015, 3:35:17 PM2/2/15
to django...@googlegroups.com
Hmmm... Try and post your urls.py and views.py (the correct one)

On Mon, Feb 2, 2015 at 5:20 PM, Dan Gentry <d...@gentryville.net> wrote:
This is a bit of a stumper!

I don't see any big glaring issues.  A couple of housekeeping things:  Is there data in the table? Are you certain that you are using the correct template?

--
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/b84e3f59-d0da-40c4-a942-81f43861a6f1%40googlegroups.com.

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

James Schneider

unread,
Feb 2, 2015, 4:18:42 PM2/2/15
to django...@googlegroups.com

You've defined your class-based view as a function:

def PozoList(ListView):

You should be defining it as a class:

class PozoList(ListView):

And you should be calling the to_view() method for the PozoList class from your urls.py.

Please post your urls.py and any traceback and error messages you are receiving.

-James

Reply all
Reply to author
Forward
0 new messages