I have a very basic contact model. The model has the following fields:
class Entry(models.Model):
name = models.CharField(max_length=64, unique=False)
organization = models.CharField(max_length=100, unique=False, blank=True, null=True)
team = models.CharField(max_length=64, unique=False, blank=True, null=True)
position = models.CharField(max_length=64, unique=False, blank=True, null=True)
address = models.CharField(max_length=130, unique=False, blank=True, null=True)
...
def __unicode__(self):
return u'%s' % self.name
I have different templates to display/edit individual entries. I'd like to accomplish the following. When viewing an individual record, I'd like the user to be able to click on "organization" and be redirected to a template that lists all of the existing records in the db from that organization. I've built the template but I'm unsure of the view code.
I feel like it should be something like this, but I don't think it's legal.
def display_organization(request):
records = Entry.objects.filter(organization__exact=Context)
t = get_template('org_list.html')
html = t.render(Context({'records': records}))
return HttpResponse(html)
Can anyone assist?