Login

Most bookmarked snippets

Snippet List

Add custom fields to the built-in Group model

Add fields and extend Django's built-in `Group` model using a `OneToOneField` (i.e. a profile model). In this example, we add a `UUIDField`. Whenever a new group is created, we automatically (via signals) create a corresponding `Role` record referencing the newly created group. Whenever a Group is deleted, the corresponding Role is deleted as well.

  • model
  • group
  • uuid
  • signals
Read More

Python Django CRUD Example Tutorial

Hey Friends, In this quick example, let's see django tutorial & crud example with mysql and bootstrap. step by step explain django crud operations with mysql backend. step by step explain django crud operations with mysql bootstrap. let’s discuss about django crud operations with mysql database. Read more... [https://tuts-station.com/python-django-crud-example-tutorial.html](https://tuts-station.com/python-django-crud-example-tutorial.html)

  • django
  • python
  • crud
Read More

Generate and render HTML Table

A set of classes that enables fast and flexible generation of HTML tables from columns definitions and datasets. With classes arguments, it is easy to style it with bootstrap for example.

  • Table
  • HTML
  • Python rendering
Read More

LazyPrimaryKeyRelatedField

When you change dynamicaly the objects manager on your Model class, you may want to have serializers take it into account.

  • DRF
  • PrimaryKeyRelatedField
Read More

CacheInDictManager

This manager use a local (in python dicts) cache for efficiency. It caches get requests and is better used with a context manager. I based my work on this previous snippet : https://djangosnippets.org/snippets/815/

  • caching
  • Django Manager
Read More

Django Standard API Response Middleware for DRF for modern frontend easy usage

I'm typescript frontend developer and i was interested in standartizing API server responses. I've tried Django for one of my projects. I've build my API and splited it into Django apps aiming at possible migration to [link >] [Microservices](https://www.youtube.com/watch?v=0iB5IPoTDts) [<] later. The problem I've faced is a difficulty of standartization API responses not only in multiple views, but for all composition of JSON-oriented django-apps which can only be made with middleware. I have put all the links to everybody could familiarize with Django framework conceptions used here. Also, I suggest to familiarize with [link >] [origin solution] (https://djangosnippets.org/snippets/10717/) [<]. The main difference is that in all my DRF JSONRenderers I do not need to wrap fields in 'result' or 'results' nested JSON. I do not get messed with result and results. If I expect an array, I just check additional pagination fields. I did not used a pagination section in my project, still i've left opportunities for that according to [link >] [origin solution] (https://djangosnippets.org/snippets/10717/) [<. Ypu can also find a paginator code fro DRF there.

  • Django
  • DRF
  • Standartization
  • Middlewares
  • Microservices
Read More

EnhancedQuerySet

A proxy for Django queryset attempting to avoid boilerplate code with ifs and avoid bugs when affectation of result is not done.

  • django query set
  • IGNORE_FILTER
Read More

Work around for negation of Q filter

It may save you some time if you're in the case of this link : https://stackoverflow.com/questions/11801363/django-q-with-joins-functioning-incorrectly-bug It worked for me at least.

  • negation
  • Q filter
Read More

3110 snippets posted so far.