Sphene Community Tools

Community

Copyright © 2007-2018 by Herbert Poul

You are not logged in.
Login
Register

Change Language:



AddThis Social Bookmark Button

A Django site.

Powered by Sphene Community Tools
Board » General » Feature Discussions » board category extensions - part 2

Hi,

I'm almost getting there with custom category extension but I've hit a problem. I can't seem to access the content of my custom category model inside my template (and probably also in my normal code).

This is my model :
class FaqPostExtension(models.Model):
post = models.ForeignKey( Post, unique = True, related_name = 'masterpost' )
status = models.IntegerField( choices = FAQ_STATUS_CHOICES, default = 1 )
summarypost = models.ForeignKey( Post, unique = True, null = True, related_name = 'summarypost' )

I then do this in my template : {% with thread.faqpostextension_set.get as faq %} but {{ faq.status }} does not return anything.

Is there way to get python/django to output the content of a model object (like thread in this example) to see what is inside ? That would make debugging this a bit easier :-)

Thanks,
Tim
Something I forgot. I can see in the database dump that my extension table contains data. So it is there.

Thanks again,
Tim
Is there way to get python/django to output the content of a model object (like thread in this example) to see what is inside ? That would make debugging this a bit easier :-)
well.. i know of no easy way to do this..

but.. my guess about your problem would be that you have defined a related name.. so .. you have to use it :)
try: {% with thread.masterpost.get as faq %} ... but.. i would definitively choose another related_name ;) (related name is the name of the reference in the target model pointing back to the model with the \ForeignKey...)

--- Last Edited by Herbert Poul at 2008-03-19 13:07:34 ---
Hey, we have Signatures !!! Great, isn't it ? ;)
but.. my guess about your problem would be that you have defined a related name.. so .. you have to use it :)
try: {% with thread.masterpost.get as faq %} ... but.. i would definitively choose another related_name ;) (related name is the name of the reference in the target model pointing back to the model with the \ForeignKey...)
Herbert Poul at 2008-03-19 13:07:34 ---
Yeah, I'll change the related_name later one. First get int working ;-).

I've been reading the django models docs and also found what you suggest. But no go. I still can't get output. To continue testing I'll delete the database and start again to make sure the database is in order.
maybe you could try the same thing in python code.. because if an exception is raised the templates usually ignore it.. but you would see it in python code..

or even better.. try it with the interactive shell ... something like..

./manage.py shell
from sphene.sphboard.models import Post
p = Post.objects.get( pk = 123 )
p.masterpost.get()


(replace 123 with the id of a post)
Hey, we have Signatures !!! Great, isn't it ? ;)
...snip...

or even better.. try it with the interactive shell ... something like..

./manage.py shell
from sphene.sphboard.models import Post
p = Post.objects.get( pk = 123 )
p.masterpost.get()


(replace 123 with the id of a post)

I need to remember this one, very handy :-)

Anyway, I've got it working. I've made 2 mistakes. The first one is that you need to do the {{ with ... }} statement after you have defined the variable you use inside the with statement (it is inside a for loop in my case).
Second is that I need to use this syntax {{ with thread.root_post.masterpost.get as faq }} because my models has a reference to a post object, not to a thread object.

Thanks for the help !
Tim
i'm wondering if you had any luck yet with your FAQ application ? how is it going ?
Hey, we have Signatures !!! Great, isn't it ? ;)

Please login to post a reply.



Powered by Sphene Community Tools