Добавление условия в DetailView django

Есть следующий класс DetailView в views:

class Watches_card(DetailView):
    model = Watches_db
    context_object_name = 'watches_model_info'
    template_name = 'watches/watches_card_published.html'
    slug_url_kwarg = 'url_watches_model'
    slug_field = 'url_watches_model'

models.py:

class Watches_db(models.Model):
    url_watches_model = models.SlugField(max_length=50, unique=True,db_index=True)
    is_published = models.BooleanField(default=True)

urls.py:

urlpatterns = [
path('watches_info/<slug:url_watches_model>/', Watches_card.as_view(), name='watches_card')]

Есть 2 шаблона (temlates):

  1. watches/watches_card_published.html
  2. watches/watches_card_not_published.html

Вопрос заклюается в том, как добавить условие в views что бы если is_published (в модели) был True, открывался шаблон watches/watches_card_published.html, если False - watches/watches_card_not_published.html

Мой вариант решения который не дал результата:

class Watches_card(DetailView):
    model = Watches_db
    context_object_name = 'watches_model_info'
    if Watches_db.is_published == True:
        template_name = 'watches/watches_card_published.html'
    else:
        template_name = 'watches/watches_card_not_published.html'
    slug_url_kwarg = 'url_watches_model'
    slug_field = 'url_watches_model'
Вернуться на верх