Hi,
Can someone tell me, how I can access all contacts relating to a specific group? I'm new to Django and did this (according to the docs):
def view_group(request, group_id):
groups = Group.objects.all()
group = Group.objects.get(pk=group_id)
contacts = group.contacts.all()
return render_to_response('manage/view_group.html', { 'groups' : groups, 'group' : group, 'contacts' : contacts })
"groups" is for something different, I tried it with "group" and "contacts" but get a
'Group' object has no attribute 'contacts'
exception.
Here's the model I'm using
from django.db import models
# Create your models here.
class Group(models.Model):
name = models.CharField(max_length=255)
def __unicode__(self):
return self.name
class Contact(models.Model):
group = models.ForeignKey(Group)
forname = models.CharField(max_length=255)
surname = models.CharField(max_length=255)
company = models.CharField(max_length=255)
address = models.CharField(max_length=255)
zip = models.CharField(max_length=255)
city = models.CharField(max_length=255)
tel = models.CharField(max_length=255)
fax = models.CharField(max_length=255)
email = models.CharField(max_length=255)
url = models.CharField(max_length=255)
salutation = models.CharField(max_length=255)
title = models.CharField(max_length=255)
note = models.TextField()
def __unicode__(self):
return self.surname
Thanks in advance!
EDIT: Oh and can someone tell me how I can add a contact to a group?