Hi Russ On Sat, 29 Jul 2006 20:46:49 +0800, Russell Keith-Magee wrote:
> On 7/29/06, Neilen Marais <[EMAIL PROTECTED]> wrote: >> >> >> I'm just testing the waters to see what people think about an extended >> ManyToManyField type that allows the addition of extra info to a link >> withouth having to use an intermediary table/model like here: >> http://www.djangoproject.com/documentation/models/m2m_intermediary/ . >> > > Hi Neilen, > > I agree that your suggestion covers a significant modelling use case. I'm > not sure I agree with your suggested syntax, but completely separate from > that issue, I can see one major problem. I'm not strongly attached to the specific syntax suggested, so let's move on :) > How do you compose a query over the intermediary model? What is the filter() > syntax that accesses the intermediary table from the models that are being > related? The existing search syntax is well suited to traversing 1-N and N-N > relations, but in N-N relations, the intermediary table is essentially > transparent. I can't see any obvious syntax extension that would allow > access to the intermediary table. My simple-minded idea is to simply have the extra link info appear as part of the tag. e.g. Image.objects.filter(tags__name='the truth, honest', tags__extra_tag_info='suspect') using the model definitions from my original post, assuming extra_tag_info is a CharField in ImageTagInfo. Similarly, it would appear as part of the image_set on Tag: Tag.objects.filter(name='the truth, honest', image_set__extra_tag_info='suspect') The idea here is that the 'extra_tag_info' applies to the specific tag/image relation, and not the tag/image itself of course. Perhaps a better field name would have been 'relation_info' rather than 'extra_tag_info'. This should be completely compatible with ordinary use of m2m relations. It would be problematic if either Tag or Image had any fields in common with ImageTagInfo, but that would presumably be checked at model creation type. One could object that this is a bit "magic" or implicit or even ambiguous. On some days I might even be inclined to agree ;) All in all it seems quite workable to me though. Another option I can think of is to add extra fields to the related models, eg. Image.objects.filter(tags__name='the truth', imagetaginfo__extra_tag_info='suspect') How to ask for this behaviour at model definition time may require some careful thought though. > Suggestions for improving this situation are welcome, but > wholesale changes to the Django query syntax are not an option - existing > models and queries must continue to work as-is. Pretty much agree violently :) Regards Neilen > > Yours, > Russ Magee %-) > you know its kind of tragic we live in the new world but we've lost the magic -- Battery 9 (www.battery9.co.za) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" 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-developers -~----------~----~----~----~------~----~------~--~---
