Sounds good!

Have a great day

On Sat, Sep 30, 2017 at 1:45 AM, Mitul Tyagi <[email protected]> wrote:

> It is done.....
> On Saturday, September 30, 2017 at 8:55:45 AM UTC+5:30, Mitul Tyagi wrote:
>>
>>
>> My form field is :
>>
>> class CityForm(forms.ModelForm):
>>     class Meta:
>>         model = City
>>         fields = ['city1', 'city2', 'city3', 'city4', 'city5', 'userName']
>>         widgets = {
>>             'city1': autocomplete.Select2(url='city-autocomplete'),
>>             'city2': autocomplete.Select2(url='city-autocomplete'),
>>             'city3': autocomplete.Select2(url='city-autocomplete'),
>>             'city4': autocomplete.Select2(url='city-autocomplete'),
>>             'city5': autocomplete.Select2(url='city-autocomplete'),
>>         }
>>
>> On Saturday, September 30, 2017 at 7:41:40 AM UTC+5:30, Constantine
>> Covtushenko wrote:
>>>
>>> Dear Mitui,
>>>
>>> I saw 2 questions in your inquiry:
>>> 1. Regarding to Form behaviour
>>> 2. Regarding to log message
>>>
>>> Let me clarify second:
>>> Provided message said that server responded with 302 - redirect response.
>>> It is correct as you said in your view method:
>>> return HttpResponseRedirect('/login/response/'+str(a.userName.username))
>>>
>>> Now is about first.
>>> You printed 'using instance argument'. I asume that you are looking of
>>> a way add user info to POST data using form. It does not work in this way.
>>> That is why user info is cleared.
>>>
>>> Initial value is used to pre populate form when it is no POST data yet,
>>> like when you generate form on GET response.
>>>
>>> To get what you need I would suggest add user info differently.
>>> You have some options here.
>>>
>>> 1 - change your form - remove user field from it. You did not provide
>>> code of your form. But I believe that you are using user field in the form.
>>> 2 - add user info to POST query. It is not recommended way as this POST
>>> QuerySet is immutable. So to do that you need to create new QuerySet from
>>> previous one and put user info there.
>>>
>>> I hope that make some sense.
>>>
>>> Regards,
>>> Constantine C.
>>>
>>> On Fri, Sep 29, 2017 at 3:11 PM, Mitul Tyagi <[email protected]>
>>> wrote:
>>>
>>>> <form role="text" action="" method="post">
>>>> {% csrf_token %}
>>>> <ul>
>>>> <li class="bar">1st City: {{form.city1}}</li>
>>>> <li class="bar">2nd City: {{form.city2}}</li>
>>>> <li class="bar">3rd City: {{form.city3}}</li>
>>>> <li class="bar">4th City: {{form.city4}}</li>
>>>> <li class="bar">5th City: {{form.city5}}</li>
>>>>
>>>> </form>
>>>> Is the template part.....
>>>>
>>>> On Saturday, September 30, 2017 at 12:16:07 AM UTC+5:30, Mitul Tyagi
>>>> wrote:
>>>>>
>>>>> Problem 1 :
>>>>> I have a model with  six fields. One is userName and other five are
>>>>> five favourite cities.....I want to update these five cities....but when I
>>>>> update them using instance argument the userName becomes NONE....I am 
>>>>> using
>>>>> the id field to update....the cities are updated for the id but the
>>>>> userName is lost. Any help for that..The code I am using is
>>>>> "
>>>>> def Update(request, city_id):
>>>>>     if request.method == "POST":
>>>>>         a= City.objects.get(pk= int(city_id))
>>>>>         print "User Updated is : ",a.userName.username
>>>>>
>>>>>         f = CityForm(request.POST, instance=a, initial={'userName.':
>>>>> str(a.userName.username)})
>>>>>         f.save()
>>>>>         return HttpResponseRedirect('/login/r
>>>>> esponse/'+str(a.userName.username))
>>>>>     else:
>>>>>         all_city = City.objects.all()
>>>>>         for city in all_city:
>>>>>             if int(city.pk) == int(city_id):
>>>>>                 a = city
>>>>>         print "User: ",a.userName.username
>>>>>         form_class = CityForm(initial={'userName': a.userName})
>>>>>         return render(request, 'formsub.html', {'form':
>>>>> form_class,'x':a.userName.username,'id':a.id})
>>>>> "
>>>>> There is an error in the method also...
>>>>> Console prints this whenever post request is made.
>>>>> " [29/Sep/2017 18:43:43] "POST /login/update/18/ HTTP/1.1" 302 0
>>>>> "
>>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/django-users/0e0dc653-92fe-4c3a-9cf5-e9d2de3cb274%40goog
>>>> legroups.com
>>>> <https://groups.google.com/d/msgid/django-users/0e0dc653-92fe-4c3a-9cf5-e9d2de3cb274%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> --
>>> Sincerely yours,
>>> Constantine C
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/e2edcae9-7b65-452c-b485-bab2289772bb%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/e2edcae9-7b65-452c-b485-bab2289772bb%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXhQ5mHUmFGzaZs8BvQrckwzHObsZrj3FpVuCcJy%2Bnx7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to