Django

Django - Reference

best practices

class DocumentUploaderFormConfig(graphene.ObjectType):
    enum_name = graphene.String(required=True)

class DocumentUploadConfigQuery(graphene.ObjectType):
    document_uploader_form_configs = graphene.List(graphene.NonNull(DocumentUploaderFormConfig)), required=True)

Django - How To

debugging/pdb for dockerised django

  1. add breakpoint() in code
  2. run the following bash command
docker container ls
docker attach ID # ID is the container id for oneview-django image

use Q & F

These two make it possible to define and reuse conditions.

use GraphiQL with django debug tool bar

  1. login to http://localhost:8000/admin/
  2. go to http://localhost:8000/graphql/
  3. copy paste both the graphql query and graphql variable from the graphql request plugin
  4. run the added query in graphiql
  5. look at the django debug toolbar

Django - Explanation

codebase uses lot of inheritances

Django likes subclassing existing class.

RelatedManager subclasses Manager to get all method from managers.

Create a manager for the reverse side of a many-to-one relation.

This manager subclasses another manager, generally the default manager of the related model, and adds behaviors specific to many-to-one relations.

https://github.com/django/django/blob/a09082a9bec18f8e3ee8c10d473013ec67ffe93b/django/db/models/fields/related_descriptors.py#L675C5-L675C45

Manager is a subclass of QuerySet so that manager has all the methods of QuerySet.

class Manager(BaseManager.from_queryset(QuerySet)): pass

https://github.com/django/django/blob/f030236a86a64a4befd3cc8093e2bbeceef52a31/django/db/models/manager.py#L176