from functools import wraps def extra_author_field(view): """ This decorator should be used in conjunction with the newforms create_update views. It adds "request.user" in the "extra_fields" dict. """ @wraps(view) def wrapper(*args, **kwargs): request = args[0] kwargs.setdefault('extra_fields', {}).update({'author' : request.user}) return view(*args, **kwargs) return wrapper #### urls.py (extract only) #### """This decorator can be used as shown below""" url(r'^add/$', # here we use both the permission_required and my new extra_author_field decorator permission_required('news.add_news')(extra_author_field(create_object)), { 'model' : News, 'model_form' : NewsForm, 'login_required' : True, }, ),