B
B
Boldy2014-12-20 13:00:32
Django
Boldy, 2014-12-20 13:00:32

Why are objects not showing up in django admin?

There is a model and its Admin:

class InviteBonus(models.Model):

    total = models.DecimalField(verbose_name='cумма платежа', blank=False, null=False, decimal_places=2, max_digits=12)
    use_date = models.DateField(verbose_name='дата платежа', blank=False)
    inviter = models.ForeignKey(TreeNode, verbose_name='пригласивший', related_name='bonuses')
    newbie = models.ForeignKey(TreeNode, verbose_name='приглашённый', related_name='awards')
    paid = models.BooleanField(default=False, verbose_name='выплачено')
    five_per_period = models.BooleanField(default=False, verbose_name='пять за период')
    line = models.PositiveIntegerField(verbose_name='линия')

class InviteBonusAdmin(admin.ModelAdmin):
    list_display = ('id', 'inviter', 'line', 'newbie', 'use_date', 'total', 'paid')
    list_filter = ('use_date', )
    search_fields = ('inviter__company_id', )

When I go to the list of InviteBonus'ov in the admin - it shows the correct number of existing objects of this model and links to go to 4 pages, but the list itself is empty. What's the matter? Moreover, if I leave only id in list_display, everything is displayed correctly

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Anatoly Scherbakov, 2014-12-20
@Altaisoft

This happens if the output of any of the fields in the table throws an exception. You yourself noted that when displaying only one id in the list_display list , everything is fine. You need to add one field to list_display and understand which of the fields gives an error.
This happened to me when using calculated fields, that is, the names of functions in list_display , if these functions threw an exception. You don't seem to have any. So this is just a guess.

M
Maxim Vasiliev, 2014-12-20
@qmax

I would guess something is wrong with TreeNode.__unicode__ The admin
calls this method to display foreign keys

A
Ali Aliyev, 2014-12-20
@ali_aliev

did you do admin.site.register?

from django.contrib import admin

from .models import InviteBonus, TreeNode


class InviteBonusAdmin(admin.ModelAdmin):
    list_display = ('id', 'inviter', 'line', 'newbie', 'use_date', 'total', 'paid')
    list_filter = ('use_date', )
    search_fields = ('inviter__company_id', )

admin.site.register(InviteBonus, InviteBonusAdmin)
admin.site.register(TreeNode)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question