On Jul 17, 2009, at 8:08 AM, Rune Bromer wrote:
> > Hello. > > For a small webshop I have the following models: Product, Category, > Country and UserProfile. Each user have a country set with a FK, and > should only be allowed to see content in the administration assigned > to the same Country. The Product and Category have FKs to the Country > model so I can ensure this by writing a "formfield_for_foreignkey" on > the ModelAdmin. So far so good, as I can also filter the admin list > view by overwriting the queryset() model on the ModelAdmin. > > The problem now is that I can assign several categories to each > Product. But I only want to allow people to see the Categories for the > same Country as the product. How is that possible. Apparently the > options for the m2m field is not filtered by the queryset and I can't > see there is a formfield_for_manytomanyfield? There is probably a way to do this if you dig deep enough into the Django code, but the admin wasn't meant for this. According to the second edition of "The Definitive Guide," the admin was meant to be an easier-to-use and less-powerful replacement for the command-line interface to your database. If you are developing in an environment where the content creators are trusted to have this kind of access, then it's an added convenience. Creating forms and modelforms is simple, and have the added benefit of being much easier to control layout. Your views could get the request.user.country and use that as an automatic filter. Shawn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---