djangopython-2.7admin

Django admin doesn't list models object but the count show there is


I have a simple model

class Professeurs(Metadata):
    nom = models.CharField(max_length=255)
    prenom = models.CharField(max_length=255)
    biographie = models.TextField()
    #photo = models.ForeignKey(image_model,blank=True)
    photo = models.OneToOneField(Photo,primary_key=True,blank=True)


    def __unicode__(self):
        return "%s  %s" % (self.nom, self.prenom)

which is registerd in the admin like that

class general(admin.ModelAdmin):
   class Media:
     js = ('/static/js/tiny_mce/tiny_mce.js', '/static/js/tiny_mce/textareas.js',)

class ProfesseursAdmin(general):
    list_display = ('prenom' , 'nom' )
    fields = ['prenom','nom', 'biographie','photo']

admin.site.register(Professeurs, ProfesseursAdmin) 

In django admin section you can just click on your model to see all the instance you have created of this model. The problem is when i create some "professeur" they don't show up in the report of the professeur admin panel. But the count show "3" so it see there is some object. I can not understand why they dont show up

Here is a picture of the problem https://dl.dropboxusercontent.com/u/14828537/Chose/Admin%20django.PNG


Solution

  • I found the problem. I did a migration and primary keys were changed because of this field:

    photo = models.OneToOneField(Photo, primary_key=True, blank=True)
    

    The primary_key=True was messing with the professeur.id