views:

637

answers:

1

Hi guys, im trying to make Categories and Subcategories, im checking this models but i have this error:

Truncated incorrect DOUBLE value: 'nacionales'

where the "nacionales" is the parent Category, i know that my problem maybe are in the urls.py, but the true, i dont know how set the urls for this case...

my model.py:

# from ...
class Categoria(models.Model):
    titulo = models.CharField(max_length=75, unique=True)
    slug = models.SlugField(max_length=200,unique=True)
    parent = models.ForeignKey('self', blank=True, null=True, related_name='child')

# functions....

my views.py:

# from ... 

def noticias_categoria(request,parent_id,child):
    categoria = get_object_or_404(Categoria,parent=parent_id,slug=child)    
    return object_list(request, queryset=categoria.noticia_set.all(), paginate_by=20,
                       template_name='categorias/categoria_list.html', 
                       extra_context={'categoria':categoria})

my Category urls.py:

# from ...
url(r'^(?P<parent_id>[-\w]+)/(?P<child>[-\w]+)/$',
                            noticias_categoria,
                            name='noticia_detail'
                            ),

my url.py:

(r'^categorias/', include('categorias.urls')),

Thanks guys

+2  A: 

It seems like you're passing in the string value of the parent category - nacionales - where the function is expecting the numeric ID.

Either use an ID for parent_id, or rename it to parent and write the first line of the function like this:

categoria = get_object_or_404(Categoria, parent__titulo=parent, slug=child)
Daniel Roseman
thansk, now is working :) ...
Asinox