开发者

Django admin page dropdowns

开发者 https://www.devze.com 2022-12-30 04:42 出处:网络
I am building a high school team application using Django. Here is my working models file: class Directory(models.Mo开发者_运维问答del):

I am building a high school team application using Django.

Here is my working models file:

class Directory(models.Mo开发者_运维问答del):
    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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号