문제

I've read this thread which deals with the issue of making Django comments use select_related() on “user” field thereby reducing needless sql queries.

The suggestion I like best is to create my own comment model and override the manager currently used.

This is what I have:

#models.py
class LightCommentManager(CommentManager):
    def get_query_set(self):
        qs = (super(CommentManager, self).get_query_set().select_related('user'))
        return qs

class LightComment(Comment):
    objects = LightCommentManager()
    class meta:
        managed = False

This all works fine but when I syncdb, Django still creates a table for LightComment. Do I really need to have this table if all I'm changing is the manager, and why does Django create it if managed is set to false?

Thanks in advance,

도움이 되었습니까?

해결책

For a start, your inner class should be called Meta, not meta.

But rather than managed = False, you should be using proxy = True to signify that you are creating a proxy model rather than another real model.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top