from django.db import models from django.utils.translation import ugettext_lazy as _ from django.conf import settings from django.db.models import permalink from django.contrib.auth.models import User
import datetime class PersonType(models.Model): title = models.CharField(max_length=100) slug = models.SlugField(unique=True) class Meta: verbose_name = _('person type') verbose_name_plural = _('person types') db_table = 'people_types' ordering = ['title'] class Admin: pass def __unicode__(self): return '%s' % self.title @permalink def get_absolute_url(self): return ('person_type_detail', None, {'slug': self.slug}) class Person(models.Model): first_name = models.CharField(blank=True, max_length=100) last_name = models.CharField(blank=True, max_length=100) slug = models.SlugField(unique=True) person_types = models.ManyToManyField(PersonType, blank=True) birth_date = models.DateField(blank=True, null=True) class Meta: db_table = 'people' ordering = ('first_name', 'last_name',) def __unicode__(self): return u'%s' % self.full_name @property def full_name(self): return u'%s %s' % (self.first_name, self.last_name) @permalink def get_absolute_url(self): return ('person_detail', None, {'slug': self.slug}) class Album(models.Model): title = models.CharField(max_length=250) slug = models.SlugField() artists = models.ManyToManyField(Person, blank=True, related_name='artists', limit_choices_to={'person_types__slug__exact': 'artist'}) composer = models.ManyToManyField(Person, blank=True, related_name='album_composer', limit_choices_to= {'person_types__slug__exact': 'composer'}) lyricist = models.ManyToManyField(Person, blank=True, related_name='album_lyricist', limit_choices_to= {'person_types__slug__exact': 'lyricist'}) class Meta: db_table = 'albums' ordering = ['title'] def __unicode__(self): return '%s' % self.title @permalink def get_absolute_url(self): return ('album_detail', None, { 'slug': self.slug }) I have 3 models PersonType, Person and Album. On a person_detail.html page I want to pull the person albums as an artist(person_type). I want to pull the person albums as an composer(person_type). I want to pull the person albums as an lyricist(person_type). or all the albums of the person he is associated with I am using the following code {% if object.album_set.all %} <ul> {% for album in object.album_set.all %} <li><a href="{{ album.get_absolute_url }}">{{ album.title }}</a></ li> {% endfor %} </ul> {% endif %} but nothing shows up, can anyone please correct me. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---