내 코드는 매우 간단합니다. 데이터베이스를 쿼리하여 향후 이벤트 목록을 가져옵니다.장고는 전날의 데이터를 표시합니다.
now = datetime.datetime.now(pytz.utc)
def index(request, listing='upcoming'):
country_name = get_client_ip(request)
if Location.objects.filter(country=country_name).count() == 0:
global_scope = True
else:
global_scope = False
if listing == 'upcoming':
if global_scope == True:
events = Event.objects.filter(date__gte=now, published=True)
else:
events = Event.objects.filter(date__gte=now, published=True, location__country=country_name)
elif listing == 'new':
if global_scope == True:
events = Event.objects.filter(published=True).order_by('-added')
else:
events = Event.objects.filter(published=True, location__country=country_name).order_by('-added')
elif listing == 'free':
if global_scope:
events = Event.objects.filter(date__gte=now, published=True, price__isnull=True)
else:
events = Event.objects.filter(date__gte=now, published=True, price__isnull=True, location__country=country_name)
elif listing == 'wishlist':
events = Event.objects.filter(users = request.user.id, published=True)
else:
events = Event.objects.filter(date__gte=now, published=True)
paginator = Paginator(events, 10)
page = request.GET.get('page')
try:
events = paginator.page(page)
except PageNotAnInteger:
events = paginator.page(1)
except EmptyPage:
events = paginator.page(paginator.num_pages)
return render(request, 'events/index.html', { "events": events, 'listing': listing, 'country_name': country_name, })
여기서 문제는 어떤 이유로 사이트가 나는 금요일에 몇 가지 이벤트와 데이터베이스를 업데이트 할 때까지, 월요일부터 보여주는 이벤트를 유지한다는 것이다.
이 사이트는 포스트 그레스에서 실행되며 django 1.6을 사용하고 있습니다. 확인해 보니 설정대로 보였습니다 default_transaction_isolation : 'read committed'가 문제를 해결할 것입니다. 그러나 postgres에 대한 설명서를 읽는 것은 그것이 기본값이라는 것을 알았습니다.
어떻게하면이 문제의 원인을 추적 할 수 있습니까?
가 정확히 어디이 코드는? 그것은 기능에 있습니까? 또는 어디에 있습니까? –
@DanielRoseman 그것은 views.py 파일 안에 있습니다. –
그 질문에 대답하지 못했습니다. * * 뷰 파일 내부 *. 함수에서? 세계적 차원에서? 클래스 선언에서? –