Re: Can't edit reverse relation in a many2many field in admin site
Thank you so very much!! It worked exactly like I wanted. I had been through the django tickets, but since this ticket has no keywords, I wasn't able to find it... It's sad to see that this is being going on for nearly 3 years!!! In my case, I had my tables 'syncdb'ed already, so it was not an issue for me. But it's well worth the effort to comment out the field definition on the second table before the 'syncdb', then remove the comment afterward. []s Nelson On Sat, Dec 6, 2008 at 4:47 AM, anode <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm not an expert either, but I think you can get what you want using > a technique from here: > http://code.djangoproject.com/ticket/897 > > Basically you just tell your Track model it's part of a many to many > relationship like this: > > class Track(models.Model): >name = models.CharField(max_length = 50) >records = models.ManyToManyField('Record', db_table = > 'music_record_tracks') > > The only issue with this is that running sync_db with this kind of set- > up might not work too well, as it would probably try to create the > intermediary many-to-many table twice. I think this will only happen > if the Track database table doesn't exist when syncdb is run, so it > should be fine in your case, but beware if you try to set up a > database from scratch. Just comment out the many-to-many field in the > Track model temporarily when you set up a new database and syncdb > should run ok. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Can't edit reverse relation in a many2many field in admin site
Hi, I'm not an expert either, but I think you can get what you want using a technique from here: http://code.djangoproject.com/ticket/897 Basically you just tell your Track model it's part of a many to many relationship like this: class Track(models.Model): name = models.CharField(max_length = 50) records = models.ManyToManyField('Record', db_table = 'music_record_tracks') The only issue with this is that running sync_db with this kind of set- up might not work too well, as it would probably try to create the intermediary many-to-many table twice. I think this will only happen if the Track database table doesn't exist when syncdb is run, so it should be fine in your case, but beware if you try to set up a database from scratch. Just comment out the many-to-many field in the Track model temporarily when you set up a new database and syncdb should run ok. On Dec 5, 6:21 pm, Nelson <[EMAIL PROTECTED]> wrote: > Hi, > > I'm fairly new to Django, so I've searched all over for an answer but > could not really find it. Maybe this is simple stuff, but anyway I > dont have enough information to judge, so I hope you guys can help > me... > > I have the following many-to-many relation: > > class Record(models.Model): > name = models.CharField() > tracks = models.ManyToManyField('Track') > > class Track(models.Model): > name = models.CharField() > > This means that a Record has multiple Tracks, and a Track can belong > to many albums (compilations). > > To make things easier for the content producers, the Record admin page > shows the m2m relation in an 'include/exclude list box', since I used > filter_horizontal = ('tracks',) in the ModelAdmin of the Record. > > However, the Track admin page DOES NOT show the 'reverse' of the many- > to-many relation. I mean, I want to display the 'include/exclude list > box' that shows all the Records, so the user can choose the ones that > the Track may belong to. > > What do I need to do to show this 'reverse' relation in the Track form > page? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~--~~~~--~~--~--~---
Can't edit reverse relation in a many2many field in admin site
Hi, I'm fairly new to Django, so I've searched all over for an answer but could not really find it. Maybe this is simple stuff, but anyway I dont have enough information to judge, so I hope you guys can help me... I have the following many-to-many relation: class Record(models.Model): name = models.CharField() tracks = models.ManyToManyField('Track') class Track(models.Model): name = models.CharField() This means that a Record has multiple Tracks, and a Track can belong to many albums (compilations). To make things easier for the content producers, the Record admin page shows the m2m relation in an 'include/exclude list box', since I used filter_horizontal = ('tracks',) in the ModelAdmin of the Record. However, the Track admin page DOES NOT show the 'reverse' of the many- to-many relation. I mean, I want to display the 'include/exclude list box' that shows all the Records, so the user can choose the ones that the Track may belong to. What do I need to do to show this 'reverse' relation in the Track form page? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~--~~~~--~~--~--~---