return u', '.join(self.facet.all()) does not work. I believe from Dive into Python .join expects a String:
"join works only on lists of strings; it does not do any type coercion. Joining a list that has one or more non-string elements will raise an exception." But in the Python docs it says .join() takes an iterable parameter. self.facets.all() is a querySet, which is definitely iterable. Basically I would like to display every field of my Sample class in the admin view, like so: Sample1 tag1 value1 tag2 value2 tag3 value3 sample2 tag1 value4 tag2 value5 Sample and tag are manytomany, and each tag should have one value at a time. It's this many to many relationship that I'm having trouble with. Am I to use inlines, the "through" attribute, write a custom method, or do I need to hack the Admin to do something which I'm thinking should be a very common thing. Thanks! On Mar 31, 3:40 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Mar 31, 8:26 pm, Daniel <unagimiy...@gmail.com> wrote: > > > > > Hi guys, > > > I'd appreciate a little advice on the following: > > > I'm trying to get a unicode string representation of my model named > > Sample. But that Sample model has a many to many relationship with > > another model, Facet. > > > So Sample's unicode method: > > > def __unicode__(self): > > return u'%s' %(self.Facet.name,) > > > This will not work in the __unicode__ method, but can someone tell me > > how to represent this? I also want to use list_display inside a > > SampleAdmin class to allow the admin site to show all the fields of my > > Sample model, but so far I can't display any many to many fields. > > > Thanks again > > You need to think about exactly you want to display here. You have a > manytomany relationship. That means that each Sample has multiple > Facets. So what do you want to show for each facet? You could join all > the facets for each sample into a comma-separated list: > > return u', '.join(self.facet.all()) > > Is that what you want? > -- > DR. -- 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.