urls.py
from django.urls import path
from . import views
urlpatterns = [
path('book/', views.ListBookView.as_view()),
]
views.py
from django.shortcuts import render
from django.views.generic import ListView
from .models import Book
# Create your views here.
class ListBookView(ListView):
template_name = 'book/book_list.html'
model = Book
models.py
from django.db import models
# Create your models here.
CATEGORY = (('business', 'ビジネス'),
('life', '生活'),
('other', 'その他'))
class Book(models.Model):
title = models.CharField('タイトル', max_length=100)
text = models.TextField()
category = models.CharField(
max_length=100,
choices =CATEGORY,
)