I'm doing a small ToDo app to start practicing some things in Django and I found this little problem that I do not know how to solve until now.
I am using python 3 and django 1.10
models.py
from django.db import models
from django.forms import ModelForm
class Item(models.Model):
title = models.CharField(max_length=255)
created = models.DateTimeField()
def __str__(self):
return self.title
class ItemForm(ModelForm):
class Meta:
model = Item
fields = '__all__'
views.py
from django.shortcuts import render
from django.views.generic import ListView, UpdateView
from .models import Item, ItemForm
class ItemListView(ListView):
template_name = 'items/items_list.html'
model = Item
class ItemAdd(UpdateView):
model = Item
template_name = 'items/item_form.html'
form_class = ItemForm
success_url = '/'
template
{% block content %}
<form action="" method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Agregar</button>
</form>
{% endblock content %}
urls.py
from django.conf.urls import url
from .views import ItemListView
urlpatterns = [
url(r'^$', ItemListView.as_view(), name="item"),
]
All this just shows me the add button that I have placed in the template, but nothing else, maybe I'm doing wrong the form's call in the template, but really no idea.
If someone helps me, I'll appreciate it: P