Hi Guys,
I'm attempting to replace the django.contrib comment app's "post_comment" using a view in views.py.
I have it working but I would like to check that I am doing it in an ok django friendly way.
The content_type that the request.POST['content_type'] returns is:
`myapp.mymodel`
When I try to use this as a content_type using: `"ContentType.objects.get_for_model(request.POST['content_type']).pk`
I get an error:
'unicode' object has no attribute '_meta'
Obviously it needs to be an object model - I need it to return an instance of *mymodel* so that I can add it to the Comment object and save it.
To get this to work I have used :
myappStr = string.split(myapp.mymodel,'.')[0]
mymodelStr = string.split(myapp.mymodel,'.')[-1]
contentType = ContentType.objects.get_by_natural_key(myappStr, mymodelStr)
This works, but I think I shouldn't need to split a string. Perhaps at some moment the content_type will actually return a model and this string split hack is going to fall apart.
Any ideas?
Many thanks!
Adam