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.
HackSoftware
/
Django-Styleguide
Django styleguide used in HackSoft projects
Django styleguide used in HackSoft projects.
Expect often updates as we discuss & decide upon different things.
If you want to check an existing project showing most of the styleguide, check the Styleguide-Example
Table of contents:
- Overview
- Cookie Cutter
- Models
- Services
- Selectors
- APIs & Serializers
- Urls
- Exception Handling
- Testing
- Celery
- Misc
- Inspiration
Overview
In Django, business logic should live in:
- Model properties (with some exceptions).
- Model
clean
method for additional validations (with some exceptions). - Services - functions, that take care of writing to the database.
- Selectors…
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
ydaniv
/
django-rest-assured
Instantly test-cover your Django REST Framework based API
django-rest-assured
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'}
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.
Hipo
/
drf-extra-fields
Extra Fields for Django Rest Framework
DRF-EXTRA-FIELDS
Extra Fields for Django Rest Framework
Usage
Install the package
pip install django-extra-fields
Note:
- Install version 0.1 for Django Rest Framework 2.*
- Install version 0.3 or greater for Django Rest Framework 3.*
Fields:
Base64ImageField
An image representation for Base64ImageField
Inherited from ImageField
Signature: Base64ImageField()
- It takes a base64 image as a string.
- A base64 image:
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
- Base64ImageField accepts the entire string or just the part after base64,
R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
- It takes the optional parameter
represent_in_base64
(False
by default), if set toTrue
it will allow for base64-encoded downloads of anImageField
. - You can inherit the
Base64ImageField
class and set allowed extensions (ALLOWED_TYPES
list), or customize the validation messages (INVALID_FILE_MESSAGE
,INVALID_TYPE_MESSAGE
)
Example:
# serializer
from drf_extra_fields.fields import Base64ImageField
class UploadedBase64ImageSerializer(serializers.Serializer)
file = Base64ImageField(required=False)
created = serializers.DateTimeField()
# use the serializer
…django-shapeshifter
A very useful Class-Based View to handle multiple forms in one view.
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.
adamchainz
/
django-perf-rec
Keep detailed records of the performance of your Django code.
django-perf-rec
"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('/')
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 = #)'
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…
Discussion (0)