DEV Community

Jeff Triplett (he/him) for Django News

Posted on • Originally published at django-news.com on

Django News #15 - 🎉 Async views are in Django 3.1. What a week, please wash your hands!

News

DjangoCon Europe 2020 is postponed to September 16-20

Current Covid-19 peak estimates are too close to the original dates (May 27-31), we can not delay making a decision anymore. Some conferences are postponing, others canceling altogether.


Google Summer of Code - Apply by March 31

Students can apply to spend 3 months working on an open source project, including Django! Last year’s GSOC student contributed JSON Field support which is a forthcoming major feature in Django 3.1.


Async views will be in Django 3.1!

Check out the pull request to see the fantastic work by Andrew Godwin and the Django team.


Articles

Google Summer of Code Reflection

Fantastic advice from Django's 2019 GSOC student.


Use python -m pip everywhere

Wise advice from Adam Johnson on managing Python dependencies.


Against service layers in Django

An in-depth piece on structuring code and logic within Django.


The most critical Python code metric

A quick and dirty way to evaluate the quality of any Python code.


How a request becomes a response: Diving deeper into WSGI

Part of an excellent series on Django and webpage internals.


Understanding many to one in Django

A deep dive on many-to-one relationships.


Website Search using Django and PostgreSQL Trigrams | Imaginary Landscape

A look at Trigrams, one of PostgreSQL's full text search features.


Layoffs are Coming

From Django co-creator Jacob Kaplan-Moss, advice on how to manage potential future layoffs in the tech space.


Sponsored Link

Django Styleguide

From HackSoft, a styleguide for Django projects at scale.


Podcasts

Django Chat - Remote Work

Remote working tips and strategies learned over the years, plus asides on self-employment and staying productive with little kids at home.


Tutorials

A Guide to ASGI in Django 3.0 and its Performance

An overview of sync vs async in Django, new features, and advice for how to structure future apps.


Django Favicon Tutorial

Quick and easy way to add Favicons to your Django project.


How to serve private media files with Django

Build a document manager with user-uploaded files and various permissions.


Projects

django-rest-assured

Instantly test-cover your Django REST Framework based API

GitHub logo ydaniv / django-rest-assured

Instantly test-cover your Django REST Framework based API

django-rest-assured

Build Downloads Latest Version License

Instantly test-cover your Django REST Framework based API.

Django-REST-Assured adds another layer on top of Django REST Framework's APITestCase which allows covering a set of RESTful resource's endpoints with a single class declaration.

This gives both a quick coverage of sanity tests to your API and a more DRY and more friendly platform for writing additional, more comprehensive tests.

As easy as

class CategoryTestCase(ReadWriteRESTAPITestCaseMixin, BaseRESTAPITestCase)
    base_name = 'category'
    factory_class = CategoryFactory
    create_data = {'name': 'comedy'}
    update_data = {'name': 'horror'}
Enter fullscreen mode Exit fullscreen mode

Django-REST-Assured is designed to work with factory_boy for mocking objects to test against. However, you can easily extend the BaseRESTAPITestCase to work directly with Django Models or any other factory.

Main features

  • Class-based declarative API for creating tests.
  • Covers the stack through: route > view > serializer > model.
  • Uses Django REST Framework's conventions to minimize configuration.
  • All tests…

drf-extra-fields

Useful extra fields for Django Rest Framework including Base64ImageField, Base64FileField, PointField, IntegerRangeField, and many more.

GitHub logo Hipo / drf-extra-fields

Extra Fields for Django Rest Framework

DRF-EXTRA-FIELDS

Extra Fields for Django Rest Framework

Build Status codecov PyPI Version Python Versions

Latest Changes

  • v3.4.1
    • Modernize the code for Python 3.7.
  • v3.4.0
    • ⚠️ BACKWARD INCOMPATIBLE ⚠️
      • Support for Django 3.0 and Django 3.1 is ended.
    • Django 4.0 is now supported.
  • v3.3.0
    • ⚠️ BACKWARD INCOMPATIBLE ⚠️
      • Support for Python 3.6 is ended.
  • v3.2.1
    • A typo in the python_requires argument of setup.py that prevents installation for Python 3.6 is fixed.
  • v3.2.0
    • ⚠️ BACKWARD INCOMPATIBLE ⚠️
      • Support for Python 3.5 is ended.
    • Python 3.9 and Python 3.10 are now supported.
    • Django 3.2 is now supported.
  • v3.1.1
    • psycopg2 dependency is made optional.
  • v3.1.0
    • Possible Breaking Change
      • In this version we have changed file class used in Base64FileField from ContentFile to SimpleUploadedFile (you may see the change here).
    • child_attrs property is added to RangeFields.

Usage

Install the package

pip install drf-extra-fields
Enter fullscreen mode Exit fullscreen mode

Note:

  • This package renamed as "drf-extra-fields", earlier it was named as django-extra-fields.
  • Install version 0.1…

django-shapeshifter

A very useful Class-Based View to handle multiple forms in one view.

GitHub logo kennethlove / django-shapeshifter

A CBV to handle multiple forms in one view

django-shapeshifter

A common problem in Django is how to have a view, especially a class-based view that can display and process multiple forms at once. django-shapeshifter aims to make this problem much more trivial.

Right now, django-shapeshifter can handle any (well, theoretically) number of forms in a single view. A view class is provided for multiple standard forms or model forms. To mix and match these form types, you'll need to do a little extra work. Here's how to use the package:

Installation

$ pip install django-shapeshifter

You should not need to add shapeshifter to your INSTALLED_APPS.

Usage

You use django-shapeshifter just like you use Django's built-in class-based views. You should be able to use the provided views with most mixins you're already using in your project, such as LoginRequiredMixin. Certain mixins may have to be refactored, such as SuccessMessageMixin, which is trigged on the form_valid() method.


django-perf-rec

Keep detailed records of the performance of your Django code.

GitHub logo adamchainz / django-perf-rec

Keep detailed records of the performance of your Django code.

django-perf-rec

https://img.shields.io/github/actions/workflow/status/adamchainz/django-perf-rec/main.yml?branch=main&style=for-the-badge https://img.shields.io/pypi/v/django-perf-rec.svg?style=for-the-badge https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge pre-commit

"Keep detailed records of the performance of your Django code."

django-perf-rec is like Django's assertNumQueries on steroids. It lets you track the individual queries and cache operations that occur in your code Use it in your tests like so:

def test_home(self):
    with django_perf_rec.record():
        self.client.get("/")
Enter fullscreen mode Exit fullscreen mode

It then stores a YAML file alongside the test file that tracks the queries and operations, looking something like:

MyTests.test_home:
- cache|get: home_data.user_id.#
- db: 'SELECT ... FROM myapp_table WHERE (myapp_table.id = #)'
- db: 'SELECT ... FROM myapp_table WHERE (myapp_table.id = #)'
Enter fullscreen mode Exit fullscreen mode

When the test is run again, the new record will be compared with the one in the YAML file. If they are different, an assertion failure will be raised, failing the test. Magic!

The queries and keys are 'fingerprinted', replacing information…

Top comments (0)