mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
had to add a magical attribute __adding on ModelForm to indicate whether we are editting or adding a model. This will be later passed into the model's .clean() method since it is necessary for correctly validating uniques (see it's current use) and can also be used to define force_insert or force_update params to model.save() Also beginning with this commit, .instance attribute is present on ModelForm and should be used to do any post-processing since manipulation of the cleaned_data will not work git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@10871 bcc190cf-cafb-0310-a4f2-bffc1f526a37
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
import sys
|
|
|
|
from django.http import HttpResponse, HttpResponseRedirect
|
|
from django import forms
|
|
from django.views.debug import technical_500_response
|
|
from django.views.generic.create_update import create_object
|
|
|
|
from models import Article
|
|
|
|
|
|
def index_page(request):
|
|
"""Dummy index page"""
|
|
return HttpResponse('<html><body>Dummy page</body></html>')
|
|
|
|
|
|
def custom_create(request):
|
|
"""
|
|
Calls create_object generic view with a custom form class.
|
|
"""
|
|
class SlugChangingArticleForm(forms.ModelForm):
|
|
"""Custom form class to overwrite the slug."""
|
|
|
|
class Meta:
|
|
model = Article
|
|
|
|
def save(self, *args, **kwargs):
|
|
self.instance.slug = 'some-other-slug'
|
|
return super(SlugChangingArticleForm, self).save(*args, **kwargs)
|
|
|
|
return create_object(request,
|
|
post_save_redirect='/views/create_update/view/article/%(slug)s/',
|
|
form_class=SlugChangingArticleForm)
|
|
|
|
def raises(request):
|
|
try:
|
|
raise Exception
|
|
except Exception:
|
|
return technical_500_response(request, *sys.exc_info())
|
|
|
|
def redirect(request):
|
|
"""
|
|
Forces an HTTP redirect.
|
|
"""
|
|
return HttpResponseRedirect("target/")
|
|
|