Tuesday, November 29, 2011

Re: A view associated with a lot of urls

Thanks !

So you'll not check if the category/item exists ( if a user enter a
bad url ), you'll just hit the database to check if it does in fact
exists ?

However with that, there is no way for example to make a difference
between "there is no items in this category" and "this category
doesn't exist" !

Well that could be a solution but only 1 collection for a lot of
different unrelated categories seems really odd to me, why not a model
per category ?

On Nov 29, 8:30 pm, DrBloodmoney <drbloodmo...@gmail.com> wrote:
> On Tue, Nov 29, 2011 at 2:19 PM, Nolhian <Eldur...@hotmail.com> wrote:
> > Thanks you for your answer, yes I plan on using different models for
> > the lookups. But I'm confused, is that a yes to my question, Lists/
> > dicts are the way to go here ?
>
> I would not do it that way. Seems incredibly brittle and you are
> mixing up you model with your view (so to speak).
>
> I would do it like so:
>
> url(r'^(?P<category>\w+)/(?P<item>\w+)/?(?P<subitem>\w+)/', view,
> name='complicated_view')
>
> and then in the view:
>
> def view(request, category, item, subitem=None):
>       MyModel.objects.get(category=category, item=item)
>
> or whatever.
>
> Then you could have urls that look like /computer/keyboard/ or
> /animal/dog/Fido, etc

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment