How To Setup Admin.Py For Django


django has built in admin feature which is one of the most useful feature. When you create a model in models.py file, it is not displayed by default in admin view. you need to register the model in `app\admin.py` file. Here is sample `admin.py` file ```python from django.contrib import admin from .models import Post,PostMeta,Tag, PostType # Register your models here. class PostAdmin(admin.ModelAdmin): list_display = ('quote_id', 'quote_title','quote_content') list_filter = ('quote_title', 'quote_content') search_fields = ('quote_title', 'quote_content') list_display_links = ('quote_id',) list_editable=( 'quote_content',) admin.site.register(Post,PostAdmin) admin.site.register(PostMeta) admin.site.register(PostType) admin.site.register(Tag) ``` In above file we have created a custom view to enable editing in main screen itself. Please note `list_display_links` and `list_editable` can not be same.

This post is written by Pravin

Tags : Django

Share it :      

Leave a comment

captcha


Tags

Elsewhere

  1. GitHub
Ad below