Web Develop

Django: Create an instance of Manager with a copy of a custom QuerySet

Sometimes we want to query by custom filter and different orders

And in this case will raise AttributeError because Queryset object can not call Manager method

Solution: as_manager()

More Django settings from document:

Django Unit Test with Fixtures

Sometimes we need to write test with initial data

For this setting as example, we can load initial data by

And we need to do setup in test cases

Django: Query from abstract model class

Abstract classes such as AbstractProduct which inherit from third party package model_utils.InheritanceManage, will not work with abstract attribute specified true:

For this reason, its subclass like ProductA will cause create issue when load fixtures data by running this command:

Which will not raise errors also not writing into database, see the same issue on stackoverflow

The solution here is provide post_save signal and execute save(), because loaddata command will not call pre_save() and save()

Django: rest_framework

ModelSerializer

data

retrieve lookup

Override APIView

permission

HyperlinkedIdentityField

MethodField

    Django Staticfiles

    urls.py

    settings.py

    collectstatics: add internal statics to external(dev) statics

    Direcotry

     

    Django User Model

    Extent User Model

    User login

    Third Part Packages

    • Django Registration Redux
    • Django All Auth
    • Python Social Auth