I'm not directly modifying any code in a .py file I am simply adding a 
value to the database table but I am unable to see the change reflected in 
my drop down lists until I restart the server.  Is there a better way of 
populating choices for my drop down menu?  Or could I simply add a cron job 
that restarts the server periodically(this seems like not a great solution).

On Saturday, June 20, 2020 at 8:39:03 AM UTC-5, Integr@te System wrote:
>
> Hi Patrick,
>
> Plz review for your suitable case:
> https://stackoverflow.com/questions/3742734/django-restart-server-or-httpd
>
> Nice.
>
> On Sat, Jun 20, 2020, 1:32 AM Patrick Carra <pcar...@gmail.com 
> <javascript:>> wrote:
>
>> I am trying to read distinct values from a model field and use the tuple 
>> list to populate the choices in a Form.  The problem I have is that every 
>> time a new value is added I must reset the httpd server in order to include 
>> the new value in the form.  I have researched and tried this a few 
>> different ways but so far am unable to come up with a better solution. Any 
>> ideas?
>>
>> *models.py*
>> class Circuitinfotable(models.Model):
>>     id1 = models.IntegerField(primary_key=True, blank=True,null=False,
>> unique=True)
>>     pathname = models.CharField(max_length=255, blank=True, null=True)
>>     segmentname = models.CharField(max_length=255, blank=True, null=True)
>>     region = models.CharField(max_length=255, blank=True, null=True)
>>
>>
>>
>>
>>
>> *forms.py*
>> def getList(item_list, keyValue):
>>     valueList=[]
>>     for each in item_list:
>>         valueList.append(each[keyValue])
>>     return valueList
>>
>> def listCreator(field, query):
>>     newList_query = getList(query, field)
>>     sorted_newList = sorted(getUnique(newList_query))
>>     sorted_newList.insert(0, ("", ""))
>>     return sorted_newList
>>
>>
>> class CircuitinfotableForm(ModelForm):
>>
>>
>>     class Meta:
>>         pathlistQuery = Circuitinfotable.objects.all().values('pathname'
>> ).exclude(pathname=None).exclude(pathname='None')
>>         path_list = listCreator('pathname', pathlistQuery)
>>
>>
>>         model = Circuitinfotable
>>         fields = ['circuitid', 'pathname', 'segmentname', 'region']
>>         widgets = {'circuitid': forms.TextInput(attrs={'size':40}), 
>> 'pathname': forms.Select(choices=path_list), 'segmentname': forms.Select(
>> choices=segment_list),
>>                    'region':  forms.Select(choices=region_list)}
>>
>> I shortened this code to only include some of the relevant fields and 
>> code for brevity.  Here I created two functions to create a list of tuples 
>> for pathname from the values I retrieve using a query and pass it to the 
>> Select widget using choices.
>>
>> -- 
>> 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...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/b63b6f32-0040-42ee-9021-e45657e9caf7o%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/b63b6f32-0040-42ee-9021-e45657e9caf7o%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/66b8fce5-43c6-48a6-a873-2527bdf2b126o%40googlegroups.com.

Reply via email to