Forums

Django - List of records in Admin just says 'object' under recent actions

I am learning Django and the list of records in Admin just says 'object' under recent actions. I am running python 3.4 and django 1.9.5. Here is my models.py.

from django.db import models

# Create your models here.
class Entry(models.Model):
    time = models.DateTimeField(auto_now_add = False, auto_now = True)
    keyword = models.CharField(max_length=30)
    jobs = models.IntegerField()
    state = models.CharField(max_length=2)

    def __str__(self):
        return self.state

[edit by admin: formatting]

With Django it's more normal to override __unicode__ rather than __str__. Try that and see if it fixes things.

No, unicode didn't work. Anything else I can try? In addition, I can only get the css to work for my template, but not for the admin section.

note: __unicode__ for python2 and __str__ for python3. also- did you restart your webapp?

Yes, restarted the webapp and still the same as before.

What happens if you change a django default one? eg: auth/users

It display the correct username and 'user'. So does this mean there was something wrong with the way I created the model?

I deleted and reinstalled my project and the objects are displayed correctly in admin. However I the css still isn't showing up in admin.

My css works after I followed this guide: https://help.pythonanywhere.com/pages/FollowingTheDjangoTutorial

Great!

There's also a guide to django static files on pythonanywhere here

I think you need to do :

def str(self): return (self.time, self.keyword, self.jobs, self.state) something like this

whatever you want it to be shown.