Created
July 9, 2009 10:27
-
-
Save riklomas/143562 to your computer and use it in GitHub Desktop.
How to default (or initial) an admin select in Django's ModelAdmin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def formfield_for_dbfield(self, db_field, **kwargs): | |
if db_field.name == "user": | |
return forms.ModelChoiceField(queryset=User.objects.all().order_by('username'), initial=kwargs['request'].user.id) | |
return super(NamedAdmin, self).formfield_for_dbfield(db_field, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment