Wednesday, November 30, 2011

Re: A view associated with a lot of urls

Well that should work pretty well with an SQL database. But as I said
my database is a NoSQL one, here I need to have one "table" per
category. So creating another Categorylist table just for fun and put
all the category names into, then hit it in order to check if the
category exists just seems wrong to me.
I thought of retrieving a list of the table names from the database
and check if the category the user want is in that list but for that I
must import another module.

On Nov 30, 1:41 pm, Ivo Brodien <> wrote:
> > I don't quite understand what you mean here. You want me to create a
> > CategoryModel of which all my Category models should be derived ? If
> > that's it, how can it help me to determine if URL is valid or not, I
> > can't see how that works.
> Sorry, it was DrBloodmoney, who wrote this:
> > class Category(models.Model):
> >    name = models.CharField.... # should be unique
> > class Item(models.Model):
> >  name = models.CharField()
> >   category = models.ForeignKey(Category, related_name='items')
> in your view you do so:
> def view(request, category, item):
>      items= get_object_or_404(Category,name=category).items().filter(name=item)
>      ....
> That's it.
> Now if someone enters a category by hand which does not exist, he gets a 404. If the category exists, but there is no item with such a name items will be empty.
> Bye
> Ivo

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment