Nevermind! Thanks to FunkyBob, I have a solution. I didn't realize you could
do this so easily, so I'll share it with others.

# views.py
def my_router(request):
    view = MyCBV.as_view(template_name = 'foo.html')
    return view(request)

Of course, I actually have logic in my function -- but I'm sure you get the
point :)

On Fri, Oct 28, 2011 at 7:09 AM, Kurtis <kurtis.mull...@gmail.com> wrote:

> Hey Guys,
>
> I'm trying to create a "router" as recommended in IRC for several
> different views. My Views are UpdateViews, so they are the new CBVs. I
> don't mind my router being a simple function based view, though.
>
> Basically, a User can edit some data. This data changes based upon the
> user's "class" ... although when I say that, it's not programmatically
> what I mean. A user can have a Band object, OR they can have a
> Musician object, or later on there'll be more choices.
>
> I want there to be one URL to edit that data. For example, they could
> go to http://www.example.com/edit-profile and based upon what type of
> an object the user has, they will be presented a specific ModelView.
> So if the user goes to that URL and they are a Musician, they will be
> presented my MusicianProfileUpdateView. If they are a Band, they will
> be presented my BandProfileUpdatedView. And so forth....
>
> I'm just really not sure what the simplest way to do this is. My views
> have quite a bit of custom logic and overrides so in a best case
> scenario, I'd be able to do the following:
>
> if Band.objects.filter(user = user).exists():
>     return BandProfileUpdateView
> elif Musician.objects.filter(user = user).exists():
>    return MusicianProfileUpdateView
>
> Currently, I just give them different URLs but I think it's a horrible
> approach from a User-experience point of view. I'm open to any
> suggestions, and if it's something pretty complex then feel free to
> throw in a short snippet example.
>
> Thanks :)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to