Django: Storing ordered, arbitrary references

Posted by Sarah on Stack Overflow See other posts from Stack Overflow or by Sarah
Published on 2010-03-17T21:44:57Z Indexed on 2010/03/17 21:51 UTC
Read the original article Hit count: 177

Filed under:

I'm new to Django, and I'm not sure what I want is possible:

I have a number of items that I want each AppUser (extended User model) to be able to reference.

That is, given an AppUser, I want to be able to extract its list of items in the way that AppUser has chosen to order them. In general, these items would actually be references to something else in the database, and this led me to one possible solution:

Store the keys for the given objects in a CommaSeparatedIntegerField in AppUser. This way, a user could have stored {7, 3, 232, 42, 1} in their items field and both the references and their preferred order would be stored. However, this feels hacky. Since most db backends store CommaSeparatedIntegerField as a VARCHAR internally, the user is not only limited by a number of objects, but also the number of digits in their chosen items. Eg. "you may store 10 items if you choose items with itemID < 10, but only 5 items if 10 < itemID < 100".

Is there a better way to do this?

© Stack Overflow or respective owner

Related posts about django