from django.db import models
class Todo(models.Model):
name = models.CharField('NAME', max_length=5, blank=True)
todo = models.CharField('TODO', max_length=50)
def __str__(self):
return self.todo
from django.contrib import admin
from todo.models import Todo
@admin.register(Todo)
class TodoAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'todo')
python manage.py showmigrations
`python manage.py makemigrations
python manage.py migrate
from django.urls import reverse_lazy
from django.views.generic import TemplateView, CreateView, ListView, DeleteView
from django.views.generic.list import MultipleObjectMixin
from todo.models import Todo
class TodoVueOnlyTV(TemplateView):
template_name = 'todo/todo_vue_only.html'
class TodoCV(CreateView):
model = Todo
fields = '__all__'
template_name = 'todo/todo_form.html'
success_url = reverse_lazy('todo:list')
class TodoLV(ListView):
model = Todo
template_name = 'todo/todo_list.html'
class TodoDelV(DeleteView):
model = Todo
template_name = 'todo/todo_confirm_delete.html'
success_url = reverse_lazy('todo:list')
class TodoMOMCV(MultipleObjectMixin, CreateView):
model = Todo
fields = '__all__'
template_name = 'todo/todo_form_list.html'
success_url = reverse_lazy('todo:mixin')
def get(self, request, *args, **kwargs):
self.object_list = self.get_queryset()
return super().get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
self.object_list = self.get_queryset()
return super().post(request, *args, **kwargs)
class TodoDelV2(DeleteView):
model = Todo
# template_name = 'todo/todo_confirm_delete.html'
success_url = reverse_lazy('todo:mixin')
def get(self, request, *args, **kwargs):
return self.delete(request, *args, **kwargs)
__all__
할 경우 전체 필드를 지정하는 것이다. reverse_lazy(url)
지정