I am new to django and I was creating a simple blog. I just added 'title', 'body', 'date' and 'time' fields. After hitting the save button, that particular post is 'added successfully' but the title of every post remains 'Post Object'. I tried 'manage.py makemigrations' and manage.py migrate commands after manage.py sync but it won't help either.
admin.py
from django.contrib import admin
from blog.models import Post
# Register your models here.
class PostAdmin(admin.ModelAdmin):
search_fields = ["title"]
admin.site.register(Post, PostAdmin)
models.py
from django.db import models
# Create your models here.
class Post(models.Model):
title=models.CharField(max_length = 140)
body=models.TextField()
date=models.DateTimeField()
def _unicode_(self):
return self.title
settings.py """
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'mysite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'mysite.wsgi.application'
# Database
# http://ift.tt/1EF8GkO
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mysite.db'
}
}
# Internationalization
# http://ift.tt/1CMZi8Y
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# http://ift.tt/1EF8GkR
STATIC_URL = '/static/'
Aucun commentaire:
Enregistrer un commentaire