apache/mod_wsgiで実行されているDjangoアプリケーションの1つで奇妙な動作に気づきました。フォームを表示する画面があります。基本的には、特定の週の容量(3サイト/週)と特定のサイトですでにスケジュールされているサイトの総数の差から計算された、特定のサイトをスケジュールするための可用性のリストを含むドロップタウンリストです。週。
このフォーム(ScheduleForm)は、次のビュー(followup / views.py)からレンダリングされます。
def schedule(request, site_id):
    site = Site.objects.get(pk=site_id)
    if request.method == 'POST':
        form = ScheduleForm(request.POST)
        if form.is_valid():
            (year, week) = request.POST['available_slots'].split('/')
            site.scheduled = week2date(int(year), int(week[1:]))
            site.save()
            return HttpResponseRedirect('/stats/')
    else:
        form = ScheduleForm()
    return render_to_response('followup/schedule_form.html',{
            'form': form,
            'site': site
        }, context_instance=RequestContext(request))
フォームクラス(followup / forms.py)は次のとおりです。
class ScheduleForm(forms.Form):
    """
    Temporary lists
    """
    schedules = Site.objects.filter(
            scheduled__isnull=False
        ).values('scheduled').annotate(Count('id')).order_by('scheduled')
    integration = {}
    available_integration = []
    # This aggregates all schedules by distinct weeks
    for schedule in schedules:
        if schedule['scheduled'].strftime('%Y/W%W') in integration.keys():
            integration[schedule['scheduled'].strftime('%Y/W%W')] += schedule['id__count']
        else:
            integration[schedule['scheduled'].strftime('%Y/W%W')] = schedule['id__count']
    for w in range(12): # Calculates availability for the next 3 months (3months*4 weeks)
        dt = (date.today() + timedelta(weeks=w)).strftime('%Y/W%W')
        if dt in integration.keys():
            capacity = 3-integration[dt]
        else:
            capacity = 3
        if capacity>0:
            available_integration.append([dt, capacity])
    """
    Form
    """
    available_slots = forms.ChoiceField(
        [[slot[0], '%s (%s slots available)' % (slot[0], slot[1])] for slot in available_integration]
    )
class IntegrateForm(forms.Form):
    integrated_on = forms.DateField(widget=AdminDateWidget())
これは実際には正常に機能しますが、唯一の問題は、サイトをスケジュールするたびにapacheプロセスを再開しない限り、サイトがスケジュールされたときに可用性のリストが更新されないことです。
これは、可用性リストがフォームクラスによってキャッシュされる場合のようなものです...
どんなアイデアでも大歓迎です。よろしくお願いします。