# bank/views.py class PostFormMixin(object): ... def get_template(self): if self.template == '': raise ImproperlyConfigured( '"template" variable not defined in %s' % self.__class__.__name__) return self.template
# bank/views.py from django.core.urlresolvers import reverse_lazy from django.views.generic import (ListView, DetailView, CreateView) from .models import Account, Transaction class AccountList(ListView): model = Account class AccountDetail(DetailView): model = Account class AccountCreate(CreateView): model = Account class TransactionCreate(CreateView): model = Transaction success_url = reverse_lazy('bank_account_list')
from django.forms import ModelForm from django.utils.text import slugify from .models import Account class AccountForm(ModelForm): class Meta: model = Account def clean(self): cleaned_data = super(AccountForm, self).clean() name = cleaned_data.get("name") slug = cleaned_data.get("slug") if not slug and name: cleaned_data['slug'] = slugify(name) return cleaned_data
from django.forms import ModelForm from django.utils.text import slugify from .models import Account class AccountForm(ModelForm): class Meta: model = Account exclude = ('slug',) def clean(self): cleaned_data = super(AccountForm, self).clean() name = cleaned_data.get("name") slug = cleaned_data.get("slug") if not slug and name: cleaned_data['slug'] = slugify(name) return cleaned_data