﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
13005	We need a way to allow for request/user specific default values in the admin fields	hejsan	nobody	"I propose a new function in line with the get_readonly_fields(self, request, obj=None) function in the ModelAdmin class.

It could have the following signature:

{{{
def default_value_for_formfield(self, request, field_name, obj=None)
}}}
And by default return None (or """") or in the case of a ModelForm, it should of return the default value of the related Model.

This is usefull because it could then be overridden in our ModelAdmin subclass to return different values dependant on for example the permissions of the currently logged in user:
{{{
def default_value_for_formfield(self, request, field_name, obj=None)
    super(NewsArticleAdmin, self).default_value_for_formfield(self, request, field_name, obj)
    user = request.user
    if not user.is_superuser:
        if 'categories' == field_name:
            if not user.has_perm('news.choose_category'):
                return PK_OF_SOME_CATEGORY
        if 'authors' == field_name:
            if not user.has_perm('news.choose_author'):
                # Can only mark him/herself as author
                return user.pk
    return super(NewsArticleAdmin, self).default_value_for_formfield(self, request, field_name, obj)

}}}

I know that this functionality could be made happen using the save_model() method of the ModelAdmin class, but this way is still prettier, it looks better to the end user to have the actual name of the category displayed instead of (None) in the case of readonly fields and reliefs any ambiguity.

This makes the new get_readonly_fields() method all the more usefull."		closed	contrib.admin	1.2-beta		wontfix			Unreviewed	0	0	0	0	0	0
