Display manytomany in list_display in django

0

I'm trying to display some cont'd items in manytomany in the list display in django, but it is returning an error, follow the codes:

Models.py

class Apenso(models.Model):

usuario = models.ForeignKey(User, blank=True)
processo = models.OneToOneField(Processo, blank=True, default=None)
apensos = models.ManyToManyField(Processo, blank=True, default=None, related_name="Apensos")

def __unicode__(self):
   return unicode(self.apenso) or u''

admin.py

class ApensoAdmin(admin.ModelAdmin):
list_display = ('processo', 'get_apensos', 'usuario')
list_display_links = list_display
list_per_page = 30
search_fields = ('processo', 'requerente__nome')

show_change_link = False

def get_apensos(self):
    return ", ".join([str(p) for p in self.apenso.all()])

And the error displayed is:

Exception Value:    
get_apensos() takes exactly 1 argument (2 given)
    
asked by anonymous 19.03.2018 / 20:42

1 answer

0

Maybe you're looking for something like:

def get_apensos(self, obj):
    return ", ".join([str(p) for p in obj.apensos.all()])

That's because I believe you want to list appended instances of the Apenso object, am I right?

    
27.03.2018 / 17:17