0

I was making a Django app. I make a Model and registered it on admin section but all I can see in admin section is message and user.

My Model is:-

class Post(models.Model):
    user = models.ForeignKey(User,related_name='posts')
    created_at = models.DateTimeField(auto_now=True)
    message = models.TextField()
    message_html = models.TextField(editable=False)
    total_votes = models.IntegerField(editable=False,default = 0)

    def __str__(self):
        return self.message

and my admin file is:-

from django.contrib import admin
from .models import Post,Comment
# Register your models here.

admin.site.register(Post)
admin.site.register(Comment)

I could not find the error can anyone help please.

If you need any extra information my repository is here

  • There's nothing wrong, it's because the other fields have `editable = False` and `auto_now = True`. EDIT: If you just want to display them, `readonly_fields` should work, according to this answer: https://stackoverflow.com/a/3967891/1081569 – Paulo Almeida Aug 31 '17 at 16:36

1 Answers1

0

Maybe you should specify what fields to display:

from django.contrib import admin
from .models import Post,Comment
# Register your models here.

class PostAdmin(admin.ModelAdmin):
    list_display = ('user', 'created_at', 'message', 'message_html', 'total_votes')

admin.site.register(Post, PostAdmin)
admin.site.register(Comment)    
Andrey
  • 111
  • 1
  • 1
  • 3