1

I have a modelChoice field in my django model class whose choices is based on another model values. each time i add new entries to the latter model, the value does not reflect on my page untill i restart the server. below is my code:

from multiselectfield import MultiSelectField
class FirstModel(models.Model):
    choices =  [(x.pk,x.subject_title) for x in Subject.objects.all()]
    choices = tuple(choices)
    subjects_to_offer = MultiSelectField(choices=choices)

class Subject(models.Model):
    # field declarations

now each time i update the Subject, the values does not reflect on the page until i restart the server. please how do i reload the First model without restarting the server. Many tanks P.S the MultiSelectField is package from https://github.com/goinnn/django-multiselectfield it is just like a choice field except it has some added features. if only i can figure a way of reloading the models without restarting the server then i'll be fine

1 Answers1

1

Yup by design, it cannot be solved this way.

The better thing would be to use a simple M2M field in models and write a custom function for saving it the way you want and in front end, make arrangements for selection of maximum number of fields.

In this case, the choices are created when the program initiates or the code is compiled.

If you have no other option, you can follow this link. Basically you will have to re-runserver on save(). This example explains that for both dev and production (apache/wsgi) server.

sprksh
  • 2,204
  • 2
  • 26
  • 43
  • +1 Updating the modification time of the wsgi file (touch in Linux) as described in the link was the only way I was able to solve this problem somewhat elegantly – Jesuisme Feb 22 '20 at 20:09