我试图制作类别和子类别,我正在检查这个模型 ,但我有这个错误:
Truncated incorrect DOUBLE value: 'nacionales'
其中“nacionales”是父类别,我知道我的问题可能在 urls.py 中,但确实,我不知道如何为这种情况设置 url...
我的模型.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....
我的意见.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})
我的类别 urls.py:
# from ...
url(r'^(?P<parent_id>[-\w]+)/(?P<child>[-\w]+)/$',
noticias_categoria,
name='noticia_detail'
),
我的 url.py:
(r'^categorias/', include('categorias.urls')),
多谢你们