spaceless_json
Now you can format and compress json-data in django template
- django
- templatetag
- json
- spaceless
- formatting
- application/id+json
Now you can format and compress json-data in django template
Takes a tweet url, requests the json from Twitter oEmbed, parses the json for the html element and returns it to your template. The html returned is ready to go and will be shown as a tweet on your web page. This uses the Requests library for Python. A full example can be found on GitHub https://github.com/z3ke1r/django-tweet-embed.
**Success Message has object properties** Success Message can have an object name or the properties of the object model to collide with the message see code below
Mixin for Django Rest Framework View/Viewsets to use different response data/serializers without unnecessary hacks. Just extend your DRFs view/viewset with this mixin after the DRF's APIView (sub)classes.
If you have a model instance you want to merge into another, it's handy to hand over all the relations into the model you want to merge into, so the deletion won't trigger cascading deletions from other tables. You can pass an `Iterable` of the same objects (a.k.a `QuerySet`) to the model, and then process it with the new model's `pk`.
create custom permissions
test
- This is a filter to shorten the natural time value obtained using naturaltime function from humanize.
This decorator is based on user_passes_test, but when a user is logged in and fails the test, it will render a 403 error instead of redirecting to login - only anonymous users will be asked to login. Version working with Django 1.11, based on version found on [https://djangosnippets.org/snippets/254/] , which is deprecated.
Using Django REST Framework for Model views there is always the issue of making duplicated queries without either prefetching the objects that will be accessed using the serializer and as such will lead to large number of queries being made to the database. This will help in optimizing the queryset used for the viewset by accessing the `_meta.fields` property of the serializer.
Provide the ability to disable a select option with Django2. This can be done during the widget initialization (i.e when the widget field is created) or during form initialization. This will disable the select option based on a context or by specifying the values that should be disabled.
Create dynamic urlpatterns for classed based views
Generate unique slug refference by another field.
use only in a dev environment. * **requirement**: Python 3.3+
Django Generic Paginator for `generic.ListView`
2955 snippets posted so far.