I can not get my models to display within the Admin Interface even after registering them in django-admin.py using admin.site.register(topic).
I have registered a model class topic, but it just isn’t showing up in the interface. Instead, I’m getting groups and users in the auth section and sites in the sites section.
Below is the code I currently have. Any help would be appreciated.
models.py
class topic(models.Model):
topic_name = models.CharField(max_length=30)
description=models.CharField(max_length=255,null=True, blank = True)
class Admin:
pass
def str__(self):
return '%s''--' %(self.topic_name)
admin.py
from django.contrib import admin
from edc.kds.models import *
if __name == "main":
management.execute_from_command_line()
admin.site.register(topic)
You’re doing some strange stuff.
1: You have some ancient, years old
class Adminsyntax which isn’t necessary.2: You have a strange
if __nameblock in there. Clearly that should raise aNameError, but assuming you actually wrote__name__ == 'main', there’s your problem.__name__is set to'main'only if the file is directly executed. If it’s executed by django machinery, the if block will never fire, and thusadmin.site.registerwill never be called.Where’d you get this idea?