skyeagle
skyeagle

Reputation: 3271

django site administration (entering fixtures data)

I have a django site. a snippet of myapp/models.py looks like this:

class Continent(models.Model):
    name = models.CharField(max_length=128, db_index=True, unique=True)


class GeographicRegion(models.Model):
    continent = models.ForeignKey(Continent, null=False)
    name =  models.CharField(max_length=128, null=False)

When I am attempting to add new geographic regions, when I click the drop down list (select control) to choose a continent, the only values (options) in the drop down list are:

continent object
continent object
continent object
continent object
continent object
continent object

I was expecting to see the names of the continents instead, so I could create relevant geographic regions per continent. How do I get the name to show in the list instead of 'continent object'?

Hint: i added str(self) and repr(self) methods to my ContinentAdmin model in myapp/admin.py like this:

myapp/admin.py

 58 class ContinentAdmin(admin.ModelAdmin):
 59    def __repr__(self):
 60        return self.name
 61 
 62 admin.site.register(Continent,ContinentAdmin)

, however this had no (observable) effect

Upvotes: 0

Views: 93

Answers (1)

Marcis
Marcis

Reputation: 4617

You need to define __unicode__ method in model:

def __unicode__(self):
  return self.name

Upvotes: 2

Related Questions