On zaterdag 23 juni 2018 14:30:08 CEST Mikkel Kromann wrote:

> In models.py:
> def GetItemPaths():    paths = [ ]
>     for i in [ 'Model1', 'Model2', 'Model3' ]:
>         p = path( i + '/list/', ItemListView.as_view(model=i), name=i +
> '_list' )
>         paths.append(p)
> 
>     return paths
> 
> However, there seems to be a problem with trying to pass the model name to
> my CBV ItemListView.
> Unless I replace the model=i with e.g. model=Model1 I get the following
> error:
> 
> 'str' object has no attribute '_default_manager'
> 
> 
> So it certainly seems that using model=i will not pass the model name.
> Is this because the argument for model= expects not a string but an object?

Yes. You can use import_module from django.functional to pass a dotted path. 
Or you can use apps.get_model() to get a model class for a app name / model 
name combo.

-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2271710.2KSSaTsjz5%40fritzbook.
For more options, visit https://groups.google.com/d/optout.

Reply via email to