views:

36

answers:

1

I am building a high school team application using Django.

Here is my working models file:

class Directory(models.Model):
    school = models.CharField(max_length=60)
    website = models.URLField()
    district = models.SmallIntegerField()
    conference = models.ForeignKey(Conference)
class Conference(models.Model):
    conference_name = models.CharField(max_length=50)
    url = models.URLField()
    class Meta:
        ordering = ['conference_name']

When I open my admin pages and go to edit a school's conference the drop down looks like this:

<select>
<option value="1">Conference Object</option>
<option value="2">Conference Object</option>
<select>

How do I replace "Conference Object" with the conference_name?

A: 

Try this:

class Conference(models.Model):
    conference_name = models.CharField(max_length=50)
    url = models.URLField()

    def __unicode__(self):
        return self.conference_name

    class Meta:
        ordering = ['conference_name']

This will say to the framework how to convert Conference instances to unicode strings.

jbochi
hey thanks so much. as I am getting off the ground here with the framework, thank you for being patient. I know I will use this again.
zen
I'm glad I could help :)
jbochi