python - Django forms initial value user_full_name -


is solution django's user_full_name initial value form? idea display django's form on end of shopping finish order. want put form total value, later. did this:

        user_dane = request.user.get_full_name         koszyk = request.session.get('koszyk', [])         produkty = list(produkt.objects.filter(pk__in=koszyk))         suma_cen = produkt.objects.filter(pk__in=koszyk).aggregate(suma=sum('cena'))         suma_wszystkich_cen = suma_cen['suma'] form=zamowienieform(initial={'imie_nazwisko':user_dane, 'kwota_do_zaplaty':suma_wszystkich_cen}) 

but working when request.method post.

if request.method =='post':         form = zamowienieform() 

according documentation shouldn't initial empty form post... there chance have user full name form?

here form class:

class zamowienieform(forms.modelform):      class meta:         model = zamowienie         fields = ('imie_nazwisko', 'kwota_do_zaplaty', 'miejscowosc',                   'ulica','numer_domu', 'numer_mi‌​eszkania', 'kod_pocztowy',)      class newmeta:         readonly = ('imie_nazwisko','kwota_do_zaplaty',) 

maybe try inside zamowienieform class

def __init__(self, *args, **kwargs):     super(zamowienieform, self).__init__(*args, **kwargs)     self.fields['imie_nazwisko'] = self.initial.get('imie_nazwisko')     self.fields['kwota_do_zaplaty'] = self.initial.get('kwota_do_zaplaty') 

although don't understand why "initial" not working out of box


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -