Hello all, when I save an object that has a ForeignKey raw_id_field, it shows the label (Unicode representation) of the related object next to the field, instead of just the field with object's PK.
I'd like to do the same thing with a ManyToMany raw_id_field (for now, just the objects' PK appear). I found out that the class responsible for this is "ManyToManyRawIdField", inside file /usr/lib/python2.4/site-packages/django/contrib/admin/widgets.py. """ class ForeignKeyRawIdWidget(forms.TextInput): [...] def render(self, name, value, attrs=None): [...] if value: *output.append(self.label_for_value(value))* return mark_safe(u''.join(output)) * def label_for_value(self, value):* key = self.rel.get_related_field().name obj = self.rel.to._default_manager.get(**{key: value}) return ' <strong>Label: %s</strong>' % truncate_words(obj, 14) class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): [...] def render(self, name, value, attrs=None): attrs['class'] = 'vManyToManyRawIdAdminField' if value: value = ','.join([str(v) for v in value]) else: value = '' return super(ManyToManyRawIdWidget, self).render(name, value, attrs) * def label_for_value(self, value):* return '' [...] """ I've to return the desired string (a concatenation of the related objects unicode representations) in method label_for_value and append it to the return of method render. But I dunno how to manipulate the object 'value' neither how to append it to the result of render, as it's done in class ForeignKeyRawIdWidget. How can I do it? Is there another way to accomplish this? Cheers! -- João Olavo Baião de Vasconcelos Bacharel em Ciência da Computação Analista de Sistemas - Infraestrutura joaoolavo.wordpress.com --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---