This may seem like a pretty basic question, but I can't seem to figure 
it out.

Is it possible to have a class's __str__ function access variables from 
other classes in a model?

For example:

class Person(models.Model):
     first_name = models.CharField(maxlength=30)
     last_name = models.CharField(maxlength=30)
     def __str__(self):
         return self.first_name + " " + self.last_name
     class Admin:
         pass

class Executive(models.Model):
     title = models.CharField(maxlength=30)
     member = models.ManyToManyField(Person)
     def __str__(self):
         return self.title + member.first_name + member.last_name
     class Admin:
         pass

This does not work. I've already tried. Sorry I don't have th error 
message anymore. I could recreate it if needed.

Does it have to do with the ManyToMany? What if it was a ForeignKey 
instead?

Thanks in advance.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to