Gday again Victor, If you think about it, the filter_horizontal widget really doesn't make sense in this context, because selecting multiple objects to link to will still require a list of them somewhere (as you mention) to set the rating. Since you like the searchability, perhaps adding an autocomplete to the inline admins would be helpful? I'm not a huge UI guy though, so maybe you're just more imaginative =D If you come up with anything, let me know.
In terms of resources, all I can recommend is reading through the source. Sorry about that! Best of luck, Brenton. On Jun 25, 12:41 pm, Victor Hooi <victorh...@gmail.com> wrote: > heya, > > Brenton: Thanks for the reply =). > > Hmm, I was hoping to use the filter_horizontal widget to set the > relationship, and just have a box below that for setting the rating. > But you're right, we'd need a table for each rating for each > relationship, and there's a room issue. > > I might look into extending the widget - is there any good > documentation on extending Django admin widgets? I saw this article: > > http://www.fictitiousnonsense.com/archives/22 > > but I'm not sure if that's still up-to-date, and I was hoping for more > details/examples to learn how to do it well. Any good reading > recommendations on this topic? > > Also, it's not so much an issue with the inlines taking up space, as > that the filter_horizontal widget, with the in-built search box, the > "choose all" and "clear all" links is just a good UI, and looks quite > nice, to boot. I'd really like to integrate it in somehow to the > inline if possible...lol. > > Anyhow, finally, thanks for the tip about __self__, completely didn't > think about that. Will set that now. > > Cheers, > Victor > > On Jun 25, 11:03 am, iliveinapark <iliveinap...@brentonannan.com> > wrote: > > > > > Gday Victor, > > > Glad you found the inline admin method for attaching your m2m's with > > throughs. It isn't possible to to use the filter_horizontal widget for > > through m2m, because, as you noted, there's no space for the extra > > fields to be input. You could always try to extend the widget, but > > this is more trouble than it's worth, and I haven't seen it done > > acceptably. If you don't like all the space taken up by the inline, > > try making them collapsible with js, maybe (you can define js in the > > ModelAdmin inner class > > Media:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-me...). > > > As for the name "FirmRating object", define a unicode method on your > > class, eg: > > > def __unicode__(self): > > return "%s - %s: %s) % (self.article, self.firm, self.rating) > > > Cheers, > > Brenton > > > On Jun 25, 10:24 am, Victor Hooi <victorh...@gmail.com> wrote: > > > > heya, > > > > Ok, scratch all that, I'm an idiot. > > > > A simple restart of my Apache process, and the m2m intermediary inline > > > works *grins*. > > > > Thanks anyhow to the awesome Django community for an awesome tool =). > > > > I do have a final question though. I can now edit "Firms" as inlines > > > from the "Article" page, which is good. > > > > However, to be honest, the filter_horizontal widget was a much better > > > interface. I suppose there's no way to somehow use the > > > filter_horizontal widget within the inline, and then tack on a > > > "Rating" field as part of the inline? > > > > Also, I notice that in my inline, it says "FirmRating object" right > > > above the select box:' > > > >http://twitpic.com/1zo4im/full > > > > Any way to hide/tweak that text? > > > > Cheers, > > > Victor > > > > On Jun 25, 10:09 am, Victor Hooi <victorh...@gmail.com> wrote: > > > > > heya, > > > > > Also, I should add I did try using the inlines as described in the > > > > docs > > > > >http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-... > > > > > In my admin.py, I've imported "FirmRating" at the top. > > > > > I've then created an inline for it: > > > > > class FirmRatingInline(admin.TabularInline): > > > > model = FirmRating > > > > extra = 1 > > > > > then used this in ArticleAdmin: > > > > > class ArticleAdmin(admin.ModelAdmin): > > > > #inlines = [ > > > > # CategoryInline, > > > > #] > > > > date_hierarchy = 'publication_date' > > > > filter_horizontal = ('firm', 'spokesperson') > > > > list_display = ('title', 'publication_date', 'entry_date', > > > > 'category', 'subject', 'source_publication', 'weekly_summary') > > > > list_editable = ('publication_date', 'category', 'subject', > > > > 'source_publication') > > > > list_filter = ('publication_date', 'entry_date', 'category', > > > > 'subject', 'source_publication') > > > > search_fields = ('title', 'publication_date', 'abstract', > > > > 'category__name', 'subject__name', 'source_publication__name', > > > > 'page_number', 'url') > > > > > However, there's still no visible widget for "FirmRating" on the "Add > > > > Article" page. > > > > > I can't tell just from the docs, but is this inline only for use on > > > > the main Article list page, but not on the Add Article page? Or is the > > > > above admin code meant to make the widget visible on the "Add Article" > > > > page as well? > > > > > Cheers, > > > > Victor > > > > > On Jun 25, 10:01 am, Victor Hooi <victorh...@gmail.com> wrote: > > > > > > heya, > > > > > > NB: This is a followup to this: > > > > > >http://groups.google.com/group/django-users/browse_thread/thread/0fdc... > > > > > > but I thought I'd also ask about the model design. > > > > > > To provide some background, we have a Django app that contains a list > > > > > of journal articles. > > > > > > Each "Article" also has a m2m relationship to "Firm" as well as > > > > > "Spokesperson" > > > > > > class Article(models.Model): > > > > > title = models.CharField(max_length=100) > > > > > publication_date = models.DateField() > > > > > abstract = models.TextField() # Can we restrict this to 450 > > > > > characters? > > > > > ...fields ommited for brevity... > > > > > firm = models.ManyToManyField(Firm, null=True, blank=True, > > > > > through='FirmRating') > > > > > spokesperson = models.ManyToManyField(Spokeperson, null=True, > > > > > blank=True, through='SpokespersonRating') > > > > > > The intermediary models, FirmRating and SpokespersonRating look like > > > > > this: > > > > > > class FirmRating(models.Model): > > > > > firm = models.ForeignKey(Firm) > > > > > article = models.ForeignKey(Article) > > > > > rating = models.IntegerField() > > > > > > Basically, we use it to store the m2m link, as well as a "rating" > > > > > assigned to each relationship. > > > > > > The issue is, as soon as I change it from a normal m2m relationship to > > > > > one with a "through" attribute, it seems to completely disappear in > > > > > the Django Admin from the "Add Article" page. Before, I had a nice > > > > > little filter_horizontal widget to create the relationships. No, > > > > > zippo...that's not a bug, is it? > > > > > > Anyhow, Firstly, am I doing this the right way? Or is there another > > > > > way to create an Article, have it m2m with Firms/Spokesperson, and > > > > > assign an individual rating to each relationship? > > > > > > Secondly, is there some way of making a m2m with intermediary visibile > > > > > in the admin - is it intended behaviour for it to disappear? In an > > > > > ideal world, I'd like to have the filter_horizontal, as well as an > > > > > inline widget to set the rating, all on the "Add Article" page. > > > > > However, I'm prepared to have just the filter_horizontal for the m2m, > > > > > and set the rating separately, on a separate page just for FirmRating/ > > > > > SpokespersonRating (it obviously breaks the workflow a bit there). > > > > > > How do people normally deal with editing m2m intermediary models in > > > > > Django? > > > > > > Cheers, > > > > > Victor- Hide quoted text - > > > > > - Show quoted text -- Hide quoted text - > > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.