Skip to content

Instantly share code, notes, and snippets.

View edraobdu's full-sized avatar

Edgardo Obregón edraobdu

View GitHub Profile
@edraobdu
edraobdu / get_queries.py
Last active March 4, 2023 14:58
pytest fixture to help debugging (and asserting) database queries on django tests.
"""
Based on this answer https://stackoverflow.com/a/59125267
Requirements:
- django
- pytest
- pytest-django
Include this fixture in your `conftest.py`
@eerien
eerien / forms.py
Last active May 12, 2024 11:20
Comma Separated Values Form Field for Django. There are CommaSeparatedCharField, CommaSeparatedIntegerField.
from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
class MinLengthValidator(validators.MinLengthValidator):
message = 'Ensure this value has at least %(limit_value)d elements (it has %(show_value)d).'
class MaxLengthValidator(validators.MaxLengthValidator):
message = 'Ensure this value has at most %(limit_value)d elements (it has %(show_value)d).'