Form does not import current data from data base

50 views
Skip to first unread message

Stefan Kusmierz

unread,
Oct 24, 2023, 12:30:02 PM10/24/23
to Django users
Dear community,
this looks like a django bug to me:
1. (see first image)
By api query I confirm that the last object of class List has the value "Startwert_neu2" in its field a, which was expected.
2. (see second image)
The form "MyForm1_2_3_4" is instantiated using exactly the same command ("List.objects.last().a") to build formchoices3 which enter the corresponding choicefield furtherdown in "MyForm1_2_3_4" (not shown in the image)
3. While running the app my print out (to find the problem) states, that formchoices3 does not contain the expected data "Startwert_neu2" but "mCP purity", which is old data from older objects. So the rendered Form also contains the old data.
To complete the information I also added snippets of views (fourth image) and models (fifth image).
Is this a known issue? 
Thanks in advance,
Stefan

DB-Query.jpgForm.jpgprint out while running.jpgsnippet from views.jpgsnippet from models.jpg

Migui Galan

unread,
Oct 24, 2023, 9:39:16 PM10/24/23
to django...@googlegroups.com
Hi Stefan!
it should be form = MyForm1_2_3_4(request.POST) where POST request will place/process the data to your form then after form.save()

--
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 django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/085fcd6d-13aa-422b-86f9-1e15c2549ac8n%40googlegroups.com.

Stefan Kusmierz

unread,
Oct 25, 2023, 4:09:32 AM10/25/23
to Django users
Hi Migui, 
I'm enchanted to receive such a quick answer.
1. It's MyForm1_2_3_4() because it's the answer to the first Get request while the page is opened
2. Why would I try to save the form to the data base?
Best regards, Stefan

Stefan Kusmierz

unread,
Oct 25, 2023, 7:21:31 AM10/25/23
to Django users
Dear community,
let me display the problem in a different way:
1. To answer the first Get request from the client the code instantiates class List and assigns a start value to the new object's field "a".
2. To answer a Post request from the client the code instantiates class List and assigns the first element of projekte_list_neto to the new object's field "a".
Either way - may it be Get or Post - the code then instantiates MyForm1_2_3_4 assigning the value of field "a" of the latest object
of class List from the database to the second element of the first tuple in formchoices3. Formchoices3 are the choices of the dropdownfield 
"my_dropdown3" in MyForm1_2_3_4.

Although the api confirms, that the latest instance of class List contains the start value ("Startwert_neu2") in its field "a", Django grabs some
older data to instantiate MyForm1_2_3_4 and renders the form with these older data to answer the first Get request.

See models-, forms- and views-files below.

Best regards,
Stefan

forms_for_userforum.jpg
models_for_userforum.jpg
views_for_userforum.jpg
Migui Galan schrieb am Mittwoch, 25. Oktober 2023 um 03:39:16 UTC+2:

Migui Galan

unread,
Oct 26, 2023, 3:27:48 AM10/26/23
to django...@googlegroups.com
Hi Stefan, sorry i thought the process you are working is in POST request. Try to place your func() after formchoices3.

Stefan Kusmierz

unread,
Oct 26, 2023, 5:00:35 AM10/26/23
to Django users
Hi Migui, thanks for your input. It didn't work.

Kani Sbt

unread,
Oct 26, 2023, 6:08:37 AM10/26/23
to django...@googlegroups.com
in django how to do phonepay integration any know or any blog or video anything , could you tell me !!! , i need  to do that payment integration in phonepay 

Stefan Kusmierz

unread,
Nov 13, 2023, 7:50:56 AM11/13/23
to Django users
Dear community,
I'd like to inform you how I overcame the problem:
instead of using
"List.objects.last().a"
to access field "a" of the last instance of class List, I did it like so:
m=List.objects.last().pk
List.objects.get(pk=m).a
Best regards,
Stefan
Reply all
Reply to author
Forward
0 new messages