9.Django admin for Web interface Background Management database

Source: Internet
Author: User

1.vim settings.py inside Open Installed_apps below django.contrib.admin (that is, uncomment)
2.vim urls.py Open the top from django.contrib import admin and Admin.autodiscover () and the following URL (R ' ^admin/', include ( Admin.site.urls)),
3.vim blog/models.py
From django.db import Models
Sex_choice= (#这里定义了一个选择的二元组, the preceding information for the display, followed by a hint
(' F ', ' Famale '),
(' m ', ' Male '),
)
Class User (Models,model):
Name = models. Charfield (max_length=30)
Sex = models. Charfield (max_length=1,choices=sex_choices)

def __unicode__ (self):
Return Self.name

4.python manage.py syncdb# Synchronization database, this synchronization found in addition to Blog_user, but also a django_admin_log, this is our corresponding to the background management of a table
5. At this point we can choose Yes to create a database administrator user, as prompted to enter information
6.python manage.py runserver# Run the development server and use the browser to test access 127.0.0.1:8000/admin/found a login interface, but there is no related blog_user table we created
7.vim blog/admin.py# This file is new
From Django.contrib Import admin
From Blog.models import User

Admin.site.register (User)
8. Re-enter the Web interface to find the Blog_user table appears, and can perform additional operations and so on, but the display is indeed the name of the user object, not intuitive, and then modify models.py
9.vim blog/models.py Add a Unicode method (added, on top)

9.Django admin for Web interface Background Management database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.