django get a wrong value after I change my Models.

0 views
Skip to first unread message

jeff jie

unread,
Sep 26, 2007, 11:04:35 AM9/26/07
to django...@googlegroups.com
hello.I am ran in truble.I change my Model,also database,but the query result is unchange..
my BlogEntry model is:

class Entry(models.Model):
    title = models.CharField('title',maxlength=100)
    content = models.TextField('content')
    catelog = models.ForeignKey(Catelog,verbose_name='catelog',null=True)
    author = models.ForeignKey(Account,verbose_name='author')
    blog = models.ForeignKey (Blog,verbose_name='belong')
    create_at = models.DateTimeField('createdtime')
    status = models.IntegerField('status')
    last_update_at = models.DateTimeField('updatedtime')
    comment_enable = models.BooleanField('allow comment')
    ip = models.IPAddressField('ip')
    comment_count = models.IntegerField('commentCount')
    editor_type = models.IntegerField ('editor_type')
    last_update_by = models.CharField('updatedby',maxlength=20,null=True)

the query is :
entries = blog.entry_set.filter(status=1).select_related(depth=1).order_by('-id')
I display the entries on the template,also display the entry's catelog name.
{{entry.catelog.name}}

I found that,because of the nullable attribute 'catelog',django send 1 + N sql stement to database.
so I have to change the attribute catelog not null:
before:
catelog = models.ForeignKey(Catelog,verbose_name='catelog',null=True)
after:
catelog = models.ForeignKey(Catelog,verbose_name='catelog')

and then i modify my database.make the catelog_id column not null.
but i find the result render on the page didn't correct.I want to get the author name by {{entry.author.name }}
actually,django print the value of {{entry.blog.caption}}.this is the problem!
I have compare the sql sent to database.the sql statment had changed.but the query reslut seems wrong.why?and how to fix ?thanks!

--
site:http://www.fallever.com
Reply all
Reply to author
Forward
0 new messages