mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	git-svn-id: http://code.djangoproject.com/svn/django/trunk@7971 bcc190cf-cafb-0310-a4f2-bffc1f526a37
		
			
				
	
	
		
			30 lines
		
	
	
		
			865 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			865 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| from django.http import HttpResponse
 | |
| from django import forms
 | |
| 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.cleaned_data['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)
 |