0

I want to cutsomize admin forms but I am lost below my code

I want to initialize pro_log with username of user connected but failed to access request object Which method I should overide and how can I get request object I've read I should override save_model or save_form methods of Modeladmin that return object but how to do that to get access to user in ModelForm?

class ProjetFormAdmin(forms.ModelForm):

    OUINON = Thesaurus.options_list(1,'fr')
    pro_nom = forms.CharField(label="Nom du projet")
    pro_log = forms.CharField(label="Log utilisateur", initial='')
    pro_act = forms.TypedChoiceField(label="Projet en cours ?", widget = forms.Select, choices = OUINON, required=False, empty_value=None)

class ProjetAdmin(SimpleHistoryAdmin):

    list_display = ('pro_nom','pro_log', 'pro_act',)
    form = ProjetFormAdmin
SLATER
  • 613
  • 9
  • 31
  • you could just get the user as a foreignKey in the project model and display in the list. – ngawang13 Jun 16 '20 at 11:28
  • I found a solution here https://stackoverflow.com/questions/1721037/remove-add-another-in-django-admin-screen/13159832 by overiding ModelAdmin get_form method – SLATER Jun 16 '20 at 15:28

0 Answers0