I am building a project which requires multiple database support. This has been relatively straightforward so far, as I can refer to the given database with aliases. For example a simple lookup uses the following view:
def index(request):
article_count = Article.objects.using('mydb_2').count()
return render_to_response('index.html',
locals(), context_instance=RequestContext(request))
However, I’m not sure how I implement the db alias reference with get_object_or_404. At the moment I have:
def article_detail(request, year, slug):
return render_to_response('article_detail.html', {
'article': get_object_or_404(Article, volume__year__exact=year, slug=slug),
}, context_instance=RequestContext(request))
Any help would be much appreciated.
Just looking at the code for
get_object_or_404I think you may be able to do: