I want to display related objects to the one a user checked out on my django site. Just like recommendation. For example, When a user click on an object in a state in Las vegas, I want other related objects in Las vegas to display by the sidebar.
Just like when a user click on a link called "home in Las vegas", and when the user is redirected to a page that display the home, and on the sidebar it display "Other homes in Las Vegas" Hope you get my point? I tried the below codes, but it's not working. Been fighting with this all day, yet no success.
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):
post=Finhall.objects.get(id=finhall_id,slug=slug) #show details of an object
stateme=Finhall.objects.get(state) #show similar objects based on state
booms=Finhall.objects.filter(state=stateme)
vips=booms.select_related()
for vip in vips:
print vip.id
return render_to_response('postdetail.html',{'post':post,'vips':vips,'Finhall':Finhall},context_instance=RequestContext(request))