0

I have a model with contains a get_slug definition:

def Specimen(models.Model):
    ...
    def get_slug(self):
        return '%s/%s-%d' % (slugify(self.longname),self.collection.collection_code, self.accessionnumber) 

In my view I want to do this:

 def show_detail(request):
    specimens = Specimen.objects.filter(...)
    specimen_data = []
    for s in specimens:
        specimen_tuple = (str(s.get_slug), format(s.latdecimal), format(s.longdecimal))
        specimen_data.append(related_tuple) 

    context['specimen_data'] = simplejson.dumps(specimen_data)

But when I try to do something with the slug in js (though I have the same result in the shell) I find something like <bound method Specimen.get_slug of <Specimen: Specimen object>> instead of my slug.

How can I force the method to be evaluated prior to passing to JSON?

Any help much appreciated.

1 Answer 1

2

Try replacing s.get_slug with s.get_slug() so that you actually call your method.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.