Designing a Tag table that tells how many times it's used

Posted by Satoru.Logic on Stack Overflow See other posts from Stack Overflow or by Satoru.Logic
Published on 2010-04-08T05:25:04Z Indexed on 2010/04/08 5:33 UTC
Read the original article Hit count: 296

Filed under:
|
|
|
|

Hi, all.

I am trying to design a tagging system with a model like this:

Tag:
   content = CharField
   creator = ForeignKey
   used = IntergerField

It is a many-to-many relationship between tags and what's been tagged.

Everytime I insert a record into the assotication table, Tag.used is incremented by one, and decremented by one in case of deletion.

Tag.used is maintained because I want to speed up answering the question 'How many times this tag is used?'.

However, this seems to slow insertion down obviously.

Please tell me how to improve this design.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about django

Related posts about database-design