I have a model with many-to-many fields and I need to get an ID selected from a many to many field. I decorated a get_absolute_url method with permaling decorator. And it doesn’t work. So I understand that I need to reverse the relation, it is obvious from the trace, but I do not really understand what should I do?
Model:
class MenuItems(models.Model):
reference_value = models.CharField(max_length=255)
filter_ids = models.ManyToManyField(Filter, blank = True)
def __unicode__(self):
return u'%s' % self.reference_value
@models.permalink
def get_absolute_url(self):
return ('homepage_ids', None, {'ids': self.filter_ids })
I tried to do with the reverse(), but I have the behavior of the method didn’t changed.
@models.permalink
def get_absolute_url(self):
return reverse('homepage_ids', kwargs={'ids': self.filter_ids })
without seeing the url pattern.
self.filter_idsdoes not return a list of ids, something like.self.filter_ids.all().values_list('id', flat=True)would return
[1,2,3]