On Fri, 2009-04-24 at 13:21 -0700, bshaurette wrote: [...] > My preference would be just to add an 'id' column to the table, but > we're trying to keep db changes to a minimum (changing one means > changing the same table in at least a dozen more - not optimal, but it > is what it is). Without it, I'm throwing "Unknown column > 'priority.id' in 'field list'" as an error. > > Each record needs to be unique on tags + content anyway. Would it be > possible to define a concatenated primary key using these two cols? > What approach would you take? (Or should I just fight a little harder > to make the adjustment to the table itself?)
I'm miles behind on my django-users reading, but saw this floating past... This isn't necessarily the happy answer, but I think table adjustments might be the pragmatic approach here unless you have many days to spend on the problem. "Faking it" for a primary key column is hard. The reason being that there is a lot of code internally which access SomeModel._meta.pk and forces that into the column list or expects it to be present when processing results. Now, I said "hard" and not "impossible", because it might be possible to make this work in a reasonably transparent fashion if you created a custom field that was the concatenation of two other fields. After all, that's kind of how GenericRelation fields work. I'd be focusing on how model instances were created (QuerySet.iterator and get_cached_row() in django.db.models.query) when testing this out if you were really motivated to do so. Multi-column primary keys is something that's been on my list for ages and the reason it's not done yet is because it's just very fiddly internally -- so many places to test and modify and assumptions to identify. Naturally you could solve your problem "properly" by making the necessary changes to Django itself and using a modified version, but, that's why I wrote the previous paragraph: it's certainly possible and not necessarily that hard (easier than trying to write a fake field that works with out-of-the-box Django, I would guess), but it would be fairly fiddly and time consuming. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

