Все что хочешь в рамках
PEP8
Я обычно делаю так:
articles/models/article.py:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
class Article(models.Model):
title = models.CharField(max_lenght=32, verbose_name=_('name'))
articles/views/article.py:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.views import generic
class ArticleMixin(object):
fields = ['title']
model = Article
paginate_by = 30
def get_success_url(self):
return reverse('articles_article_index')
class Index(ArticleMixin, generic.ListView):
template_name = 'articles/index.html'
class Create(ArticleMixin, generic.CreateView):
template_name = 'articles/create.html'
class Update(ArticleMixin, generic.UpdateView):
template_name = 'articles/update.html'
class Delete(ArticleMixin, generic.DeleteView):
template_name = 'articles/delete.html'
index = Index.as_view()
create = Create.as_view()
update = Update.as_view()
delete = Delete.as_view()
articles/urls.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf.urls import url
from django.conf.urls import patterns
from articles.views import article
urlpatterns = patterns('',
url(r'^$', article.index, name='articles_article_index'),
url(r'^update/(?P<pk>[\w-]+)/$', article.update, name='articles_article_update'),
url(r'^delete/(?P<pk>[\w-]+)/$', article.delete, name='articles_article_delete'),
url(r'^create/$', article.create, name='articles_article_create'),
)