Answer the question
In order to leave comments, you need to log in
How to pass data from multiple models to DetailView?
views.py
class DetailView(DetailView):
model = Page
context_object_name = 'Page'
template_name = 'page/pagescr.html'
from django.contrib import admin
from django.urls import path
from django.conf.urls import include
from page import views
urlpatterns = [
path('admin/', admin.site.urls),
path('grappelli/', include('grappelli.urls')), # grappelli URLS
path('', views.index, name='index'),
path('<slug:slug>/', views.DetailView.as_view(), name='pagesc'),
]
class Page(models.Model):
page_title = models.CharField('Title страницы', max_length = 200)
slug = models.SlugField('URL страницы', primary_key=True, max_length=250, unique=True)
page_text = models.TextField('Содержимое страницы')
def __str__(self):
return self.page_title
def get_absolute_url(self):
return reverse('detail', args=[str(self.slug)])
class Content(models.Model):
info = models.CharField(max_length = 200)
ban_scr_sc = models.CharField(max_length = 200)
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