Answer the question
In order to leave comments, you need to log in
How to get get_absolute_url of the same model but from different url names?
How to get get_absolute_url of the same model but from different url names?
I have a StandardModel that contains cabinets.
These cabinets are categorized. Categories are written in the field with a choice
type_case = models.CharField(max_length=10, choices=TYPE_CASE, default='case', verbose_name='Тип корпуса')
path('base/<b>case</b>/<int:pk>/', views.BasicItemView.as_view(), {'filter': 'case'}, name='<b>basiccaseitem</b>'),
path('base/<b>built-in</b>/<int:pk>/', views.BasicItemView.as_view(), {'filter': 'built-in'}, name='<b>basicbuiltinitem</b>'),
def get_absolute_url(self):
return reverse('basiccaseitem', args=[str(self.pk)])
class StandardModel(models.Model):
'Базовые шкафы'
title = models.CharField(max_length=200, verbose_name='Название')
article = models.CharField(max_length=10, unique=True, verbose_name='Артикул')
qdoors = models.SmallIntegerField(choices=QUANTITY_DOORS, default=2, verbose_name='Количество дверей')
type_case = models.CharField(max_length=10, choices=TYPE_CASE, default='case', verbose_name='Тип корпуса')
.....
def get_absolute_url(self):
return reverse('basiccaseitem', args=[str(self.pk)])
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
path('base/case/', views.BasicView.as_view(), {'filter': 'case'}, name='basiccase'),
path('base/case/<int:pk>/', views.BasicItemView.as_view(), {'filter': 'case'}, name='basiccaseitem'),
path('base/built-in/', views.BasicView.as_view(), {'filter': 'built-in'}, name='basicbuiltin'),
path('base/built-in/<int:pk>/', views.BasicItemView.as_view(), {'filter': 'built-in'}, name='basicbuiltinitem'),
path('base/doors/', views.DoorsView.as_view(), name='doors'),
path('base/doors/<int:pk>/', views.DoorsItemView.as_view(), name='doorsitem'),
path('works/', views.WorksView.as_view(), name='works'),
path('works/<int:pk>/', views.WorksItemView.as_view(), name='worksid'),
]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question