• django学习笔记(2)


    Part 2: The admin site

    ====> Creating an admin user
    $ python manage.py createsuperuser
       Username: admin
       Email address: admin@example.com
       Password: **********
       Password (again): *********
       Superuser created successfully.


    ====> Start the development server
    $ python manage.py runserver



    ====> Enter the admin site
    (http://127.0.0.1:8000/admin/)


    ====> Make the poll app modifiable in the admin
    $ edit pollsadmin.py

    from django.contrib import admin

    from .models import Question

    admin.site.register(Question)



    ====> Explore the free admin functionality



    ====> Customize the admin form
    $ edit pollsadmin.py

    from django.contrib import admin

    from .models import Question


    class QuestionAdmin(admin.ModelAdmin):
        fields = ['pub_date', 'question_text']

    admin.site.register(Question, QuestionAdmin)





    ====> Split the form up into fieldsets
    $ edit pollsadmin.py

    from django.contrib import admin

    from .models import Question


    class QuestionAdmin(admin.ModelAdmin):
        fieldsets = [
            (None,               {'fields': ['question_text']}),
            ('Date information', {'fields': ['pub_date']}),
        ]

    admin.site.register(Question, QuestionAdmin)




    ====> Assign arbitrary HTML classes to each fieldset
    $ edit pollsadmin.py

    from django.contrib import admin

    from .models import Question


    class QuestionAdmin(admin.ModelAdmin):
        fieldsets = [
            (None,               {'fields': ['question_text']}),
            ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
        ]

    admin.site.register(Question, QuestionAdmin)



    ====> Adding related objects
    $ edit pollsadmin.py

    from django.contrib import admin

    from .models import Choice, Question
    # ...
    admin.site.register(Choice)


    ====> Remove the register() call for the Choice model. Then, change the Question registration code
    $ edit pollsadmin.py

    from django.contrib import admin

    from .models import Choice, Question


    class ChoiceInline(admin.StackedInline):
        model = Choice
        extra = 3


    class QuestionAdmin(admin.ModelAdmin):
        fieldsets = [
            (None,               {'fields': ['question_text']}),
            ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
        ]
        inlines = [ChoiceInline]

    admin.site.register(Question, QuestionAdmin)




    ====> Change the display style of the related objects in a more compact, table-based format
    $ edit pollsadmin.py

    class ChoiceInline(admin.TabularInline):
        #...



    ====> Customize the admin change list -- use the list_display admin option
    $ edit pollsadmin.py

    class QuestionAdmin(admin.ModelAdmin):
        # ...
        list_display = ('question_text', 'pub_date', 'was_published_recently')



    ====> Add a “Filter” sidebar -- using the list_filter admin option
    $ edit pollsadmin.py

    class QuestionAdmin(admin.ModelAdmin):
        # ...
        list_filter = ['pub_date']


    ====> Add some search capability
    $ edit pollsadmin.py

    class QuestionAdmin(admin.ModelAdmin):
        # ...
        search_fields = ['question_text']





    ====> Customize the admin look and feel

    ====> Customizing your project’s templates
    $ mkdir templates
    $ edit mysitesettings.py
    TEMPLATES = [
        {
            # ...
            'DIRS': [os.path.join(BASE_DIR, 'templates')],
            # ...
        },
    ]
    $ mkdir templatesadmin
    $ copy C:python34libsite-p~1djangocontribadmin emplatesamdinase_site.html templatesadminase_site.html
    $ edit tempaltesadminase_site.html
    # replace {{ site_header|default:_('Django administration') }} with Polls Administration
    # ...
    {% block branding %}
    <h1 id="site-name"><a href="{% url 'admin:index' %}">Polls Administration</a></h1>
    {% endblock %}
    # ...




    ====> Customizing your application’s templates



    ====> Customize the admin index page


  • 相关阅读:
    error LNK2001: unresolved external symbol "public: __thiscall ControllerInterface::ControllerInterface(class QObject *)" (??0ControllerInterface@@QAE@PAVQObject@@@Z) downloadcontroller.obj
    链接程序的时候遇到问题:fatal error LNK1104: cannot open file 'rctrl-d.lib'
    vs编译报错 BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
    qt 编译unresolved external symbol的错误解决
    程序外框不显示
    Pc移植到Mac的技术细节
    qt中moc的作用
    做回自己,保持作为一个男人的魅力是维持一个维持一段恋爱关系长久的前提
    NLP入门(三)词形还原(Lemmatization)
    NLP入门(二)探究TF-IDF的原理
  • 原文地址:https://www.cnblogs.com/hhh5460/p/4460422.html
Copyright © 2020-2023  润新知