Daniel, Now we're cooking. You were quite right. A red herring that I had the wrong syntax. The function list2text was not correct. It had been correct but for whatever reason I didn't notice that I messed up a tab key (in Python) and it was not computing correctly (whereas at one point it was). I fixed the missing tab and I put a few more bits of defensive coding. Thanks!
On Aug 9, 12:55 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Aug 9, 12:42 pm, rmschne <rmsc...@gmail.com> wrote: > > > > > > > I'm looking for the right syntax for inside a template to display a > > model variable that is actually not a field in the database (defined > > by the mode), but a Model method. > > > Class Member(model.Models): > > id = models.IntegerField(primary_key=True, db_column='ID') > > lname = models.CharField(max_length=150, db_column='LName', > > blank=True) > > fname = models.CharField(max_length=150, db_column='FName', > > blank=True) > > .... (plus other fields) > > > def contactslistindirectory(self): > > """Returns a comma deliminted list of all member contacts > > (with last contact prefixed by and)""" > > s1=self.contacts.all().filter(indirectory=True) > > s=list2text(s1) > > return s > > > The model method "contactslistindirectory() returns a string of the > > name of the contacts for that member. It's getting that information > > from another model called Contact which has a ForeignKey connection > > back to Member. > > > I have a template working that can display {{ member.lname }}, > > {{member.fname }} and others. The template loops through all > > members. > > > I want to display in the template for each member the value of what is > > in contactslistindirectory. I've tried > > {{ member.contactslistindirectory }} and that doesn't work. I don't > > know the syntax for displaying the value of a Model Method in a > > template. I'm sure the answer is right in front of me, but despite > > searching the documentation for examples, I can't spot it. I can see > > how the model methods are defined, but as yet have not seen how to use > > that in a template. > > > Any pointers? > > {{ member.contactslistindirectory }} is the correct syntax. There must > be something wrong with the method - perhaps the filter is not > returning any results, or perhaps list2text is incorrect. > > You might try debugging by putting a 'print s' before the return > statement in your method, and seeing what that prints in the console. > -- > DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---