I'm using django administration view. I have a article model. Each article has a title, body, datetime, slug and a rating. By default, django make a form for creating a new article. I only want fields for title and body but django creates fields for everything. I wan't to hide the slug field. How can I hide or customize the admin new article view?
Here Is my model.py
from django.db import models
from django.core.urlresolvers import reverse
class Article(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(unique = True, max_length = 255)
body = models.TextField()
created = models.DateTimeField(auto_now_add = True)
rating = 0
class Meta:
ordering = ['-created']
exclude = ('rating')
def __unicode__(self):
return self.title
def get_absolute_url(self):
return reverse('article.views.article', args=[self.slug])
UPDATE 7 MAY: I tried to specify the fields in my admin.py, to get it to work I had to remove prepopulated_fields for my slug. That lead to a post without a slug. Isn't there a way to get the title to a slug without a field for it?
Here is my original admin.py.
from django.contrib import admin
from article.models import Article
# Register your models here.
class ArticleAdmin(admin.ModelAdmin):
# fields display on change list
list_display = ['title', 'body']
# fields to filter the change list with
list_filter = ['created',]
# fields to search in change list
search_fields = ['title', 'body']
# enable the date drill down on change list
date_hierarchy = 'created'
# prepopulate the slug from the title - big timesaver!
prepopulated_fields = {"slug": ("title",)}
admin.site.register(Article, ArticleAdmin)