-1

I have a model called Finhall and fields under it. But in my view I want to get the value of state field the user clicked on in order to filter other places in that same state. After trying this codes, I'm getting the below error:

                  global name 'finhall' is not defined

Models

class Finhall(models.Model):
    user=models.ForeignKey(User)
    name=models.CharField(max_length=250, unique=True)
    address=models.CharField(max_length=200)
    city=models.CharField(max_length=200)
    state=models.CharField(max_length=200, help_text='Las vegas')

    def __unicode__(self):
        return u'%s' % (self.name)

Views

def homedetail(request,finhall_id,slug):
     qs=Finhall.objects.all()

     try:
         post=qs.get(id=finhall_id,slug=slug)
     except Finhall.DoesNotExist:
         post=None

     if post:
        similar_posts=qs.filter(finhall.state) #this line is causing the error

     else:
        similar_posts=Finhall.objects.none()
     return render_to_response('homedetail.html',{'post':post,'similar_posts':similar_posts},context_instance=RequestContext(request))

I've been trying to fix this error all day yet no success!

4

2 回答 2

1

下面是我修复的行:

   similar_posts=qs.filter(state=post.state) 

感谢马蒂亚斯的想法!

于 2013-04-30T06:54:59.653 回答
0

您是否已导入库?

from app.models import Finhall

复制您的模型以获取更多信息。

于 2013-04-21T13:41:21.870 回答