Brenden
Brenden

Reputation: 8764

Use different view depending on object model database value in Django

I am launching a 2nd version of a project, and I want the users to be able to upgrade to the new format. It's not going to be a forced upgrade, so essentially, users will say "Make my page a V2 page". The URLs for their pages will stay the same.

I'd like to be able in the view to say:

def v1_page(request, page_id):
    page = get_object_or_404(Page, id=page_id)
    if page.upgraded:
        # use the v2 view instead (which ends with a return render_to_response('v2_base_page.html', variables))
        v2_page(request, page)
    else:
        # load this page 

Or am i going about it the wrong way? I dont want a massive if/else statement.

Upvotes: 1

Views: 103

Answers (1)

Alexey Savanovich
Alexey Savanovich

Reputation: 1903

Function should return result of v2_page call:

def v1_page(request, page_id):
    page = get_object_or_404(Page, id=page_id)
    if page.upgraded:
        return v2_page(request, page)
    else:
        # load this page 

Upvotes: 2

Related Questions