Model:
class Specialization(models.Model):
SPECIALIZATION_TYPE = (
('S','Specialty'),
('Ss','Sub-specialty')
)
specialization_desc = models.CharField('Specialization',max_length=50,unique=True)
specialization_type = models.CharField(max_length=2, choices=SPECIALIZATION_TYPE)
active = models.BooleanField('Active',default=True)
def __unicode__(self):
return self.specialization_desc
class Person(models.Model):
GENDER = (
('M','Male'),
('F','Female'),
)
first_name = models.CharField("First Name", max_length=50)
last_name = models.CharField("Last Name",max_length=50)
middle_name = models.CharField("Middle Name", max_length=50, blank=True)
specialization_id = models.ManyToManyField(Specialization,
Template:
{% for per in person_list%}
<tr>
<td>{{ per }}</td>
{% for spec in per.specialization_id.all %}
<td>{{ spec }}</td>
{% endfor %}
</tr>
{% endfor %}
View:
p = Person.objects.all()
return p
I would Like to see a table like this:
FullName | Specialization |
My Name | Programming, Web Development |
I'm getting this instead
FullName | Specialization |
My Name | Programming | Web Development
- Storing spec in a variable is not possible accdg to articles that I've read, that alone should have solved my problem
- Storing data in dictionary from views is giving me object Person is not callable
Seems a dead end for me. Ideas?