Dear Ivan, your help is priceless, thanks!

Ivan Sagalaev wrote:
[...]
> In models.py you can get rid of repeating "Manufacturer" two extra times 
> by doing:
> 
>      class Manufacturer(models.Model):
>          name = models.CharField(max_length=30)
>          address = models.CharField(max_length=50)
> 
>      admin.site.register(Manufacturer, admin.ModelAdmin)

> Also you can register admins for all models in a loop:

Done, it works great.

> > Isn't there sort of a wildcard or shortcut to catch all those
> > cases at once?
> 
> You can make one yourself through some python-fu:
> 
>      (r'(?P<model>\w+)/?$', model_view(list_detail.object_list)),
>      (r'^(?P<model>\w+)/(?P<object_id>\d+)/?$', 
> model_view(list_detail.object_detail)),
>      (r'^(?P<model>\w+)/create/?$', model_view(create_object)),
>      (r'^(?P<model>\w+)/update/(?P<object_id>\d+)/?$', 
> model_view(update_object)),
> 
> "Model_view" here is a decorator that would take model name from 
> argument and turn it into a respective queryset:
> 
>      # mapping from lowercased names of models to models
>      from django.db.models import Model
>      import models
>      model_classes = dict(
>          (i.__class__.__name__.lower(), i)
>          for i in dir(models)
>          if isinstance(i, Model)
>      )
> 
>      def model_view(func):
>          def wrapper(request, *args, **kwargs):
>              model = kwargs.pop('model')
>              kwargs['queryset'] = model_classes[model].objects.all()
>              return func(request, *args, **kwargs)
>          return wrapper

This is the urls.py I created: http://dpaste.com/72138/
It doesn't work though: I get a
KeyError at /manufacturer
u'manufacturer'
when accessing http://localhost:8000/manufacturer
(manufacturer being one of my model)

Thank you very much for any further help,
Fabio.

-- 
fabio natali
http://poisson.phc.unipi.it/~natali

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to