So I am using Djangos builtin comments app (django.contrib.comments) for my blog application. I made several changes to the forms display, etc. (as described in the documentation). One last thing that bothers me is that the Comments model is in it's own category in the admin, like this:
MyApp
---Model1
---Modle2Comments
---Comments
I want it to be like this since the comments are tied to the MyApp models.
MyApp
---Model1
---Modle2
---Comments
I tried to achieve this by adding this line of code to MyApps admin.py (overwriting the Comment class)
class MyAppComment(Comment):
class Meta(Comment.Meta):
app_label = 'myapp'
admin.site.unregister(Comment)
admin.site.register(MyAppComment, CommentsAdmin)
And this works (and the Comments model shows up under MyApps) but now the links are wrong...the model points to:
which outputs an error:
no such table: myapp_myappcomment
instead of:
This is because the admin forms it's urls according to app names and model names...how could I just change the position of the Comments model in the admin but leave the urls as they are?
There must be some way to do it?
You haven't 'overwritten' the Comment
class -- by subclassing it, you've actually created a child model using multi table inheritance. This is why another table needs to be created.
You could create a proxy model that inherits from the Comment
class, then no additional tables need to be created.
class MyAppComment(Comment):
class Meta(Comment.Meta):
proxy = True
admin.site.unregister(Comment)
admin.site.register(MyAppComment, CommentsAdmin)
You shouldn't need to set app_label
if MyAppComment
is defined in the myapp
app - it will be set automatically.