0

I have written a small django app and in it I can upload some documents and at another point I can make a reference from a payment to the corresponding document. But my problem is that the list of documents is always outdated. But when I kill my gunicorn and start the webserver again, then the dropdown list with documents loads correctly and also shows the newest file uploads.

Do you have an idea why Django behaves like that?

Best regards

Edit: I just saw that I have to edit this question.

So I have this in my forms.py:

dms_objects = dmsdok.objects.all().order_by('-id')
choices_dms = []
for dms_obj in dms_objects:
    choices_dms.append((dms_obj.id, dms_obj.dms_dok_titel))

And also I have this in the form:

 zahlung_dok_pseudo_fk = forms.IntegerField(required=False, widget=forms.Select(attrs={'class':'form-control',}, choices= choices_dms), label='Zugehörigkeit Dokument')

I guess that this is what Willem means, but I do not know how I must change that.

MDoe
  • 163
  • 1
  • 13
  • That is likely because you stored a `QuerySet` somewhere as a variable at module level. – Willem Van Onsem Nov 06 '20 at 16:27
  • Dear Willem, thanks, but could you elaborate on that? I am not so experienced and still learning. – MDoe Nov 07 '20 at 11:59
  • Please, could anyone be so kind and explain that to me? – MDoe Nov 10 '20 at 13:41
  • I guess, Willem means this: In my forms.py I have dms_objects = dmsdok.objects.all().order_by('-id') choices_dms = [] for dms_obj in dms_objects: choices_dms.append((dms_obj.id, dms_obj.dms_dok_titel)) and later in the form: zahlung_dok_pseudo_fk = forms.IntegerField(required=False, widget=forms.Select(attrs={'class':'form-control',}, choices= choices_dms), label='Zugehörigkeit Dokument') But how could I change that to be updated on each request? – MDoe Nov 10 '20 at 13:46
  • I solved it by following this advice: https://stackoverflow.com/questions/36271560/passing-objects-to-a-django-form – MDoe Nov 15 '20 at 16:08

0 Answers0