See ticket #6095. There's been quite a bit of discussion about it, including a bit on django-dev.
Cheers, Cliff On Sat, 2008-01-05 at 00:32 -0800, Topher wrote: > Okay, I found one workaround in the archives (http://groups.google.com/ > group/django-users/browse_thread/thread/11d4a135c929ab7d). The > workaround is to instantiate the mapping as a model class in and of > itself, e.g.: > > class MappingAlbumSong(models.Model): > song = models.ForeignKey(Song) > album = models.ForeignKey(Album) > track_number = models.IntegerField() > > However, this seems clunky and inelegant -- at this point it's just an > exact duplication of the database tables, and the application loses > some of the nice abstraction of many-to-many relationships that I saw > as the point of using Django's model system in the first place. It > also makes more work on the code side since (I think) I would have to > modify both the Album and Song models to contain a MappingAlbumSong > field, complicating queries for data like an album's tracklist ordered > by track number (which is the primary task I want to accomplish). > > Does anyone else have ideas or suggestions? Any help would be > appreciated! > > On Jan 4, 11:58 pm, Topher <[EMAIL PROTECTED]> wrote: > > Hi, I am new to Django, so please forgive me if my question is very > > basic and/or stupid. > > > > I would like to keep track of Song and Album models, with a many-to- > > many relationship between the two (albums contain multiple songs, and > > songs can appear on multiple albums). > > > > class Song(models.Model): > > title = models.CharField(max_length=300) > > > > class Album(models.Model): > > title = models.CharField(max_length=300) > > tracks = models.ManyToManyField(Song) > > > > What I'd like to do is have the ManyToManyField have some notion of > > what track number a song is on an album. This isn't information that > > can be contained in the Song model since songs are assigned different > > track numbers on different items. When I've dealt with such matters > > in the past, I would set up a MySQL table with fields 'song_id', > > 'album_id', 'track_number', and would thereby be able to do tasks like > > getting a song's track number on any given album and getting a list of > > songs sorted by track number.for a given album. Is there a way to > > accomplish these tasks in Django? I expected some sort of ability to > > add extra fields to the relationship table when declaring a > > ManyToManyField, but so far have not been able to find any > > documentation on anything like that. > > > > Thank you for the help! Again, I'm new to all this, so I apologize if > > this is covered in some bit of documentation I missed; if that's the > > case, a link to the right page would be much appreciated. > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

