Display manytomany on list_display on Django

Asked

Viewed 327 times

0

I am trying to display some items in manytomany in the list display on Jango, 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)
  • Man, basically he is complaining that two arguments were passed to the function "get_apensos()", when in fact he only expects one. Are you sure you’re breaking this part of the code?

  • I checked here, and there’s only get_attached to that part of the code, there’s nowhere else

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()])

This is because I believe you want to list the appendages of the object instance Apenso, I’m sure?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.