Created
September 19, 2020 19:58
-
-
Save cKurultayKalkan/917d7d33c390297c9a7604c1b128b0ea to your computer and use it in GitHub Desktop.
Django Helper
This file contains hidden or 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
| # Initial Value For Foreign Keys | |
| class MyModelAdmin(admin.ModelAdmin): | |
| def formfield_for_foreignkey(self, db_field, request, **kwargs): | |
| if db_field.name == 'author': | |
| kwargs['initial'] = request.user.id | |
| return super(MyModelAdmin, self).formfield_for_foreignkey( | |
| db_field, request, **kwargs | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment