Tuesday, November 29, 2011

Re: A view associated with a lot of urls

On Tue, Nov 29, 2011 at 3:37 PM, Nolhian <Eldurian@hotmail.com> wrote:
> 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 ?

No I don't know what your business logic for the view/model would be.
I was just showing an example of how you could take keywords from your
request url and map them to your models to display results to the user
without having to hard-code them in your urls or settings or whatever.


> 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 ?

Again it's however you want to model your data. For the sake of
normalization (and typing/database size/etc) I'd probably have one
model for categories:

class Category(models.Model):
...

class Item(models.Model):
category = models.ForeignKey(Category, related_name='items')
...

and so forth.

--
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