codigo alto nivel
es solo un ejemplo
es solo un ejemplo
This is an updated of version snippets: * [https://djangosnippets.org/snippets/10489/](https://djangosnippets.org/snippets/10489/) * [https://djangosnippets.org/snippets/1376/](https://djangosnippets.org/snippets/10489/) Tested to with with Django 3.2 With this template loader you can extend templates from built-in Django apps such as Django admin. Example: {% extends "admin:admin/index.html" %} {% block sidebar %} {{block.super}} <div> < h1>Statistics< /h1> < a href="/admin/station/stats/">Published Stations< /a> </div> {% endblock %} Configuration: TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ 'your_app/templates' ], 'OPTIONS': { # (...) # See: https://docs.djangoproject.com/en/3.2/ref/templates/api/#django.template.loaders.cached.Loader 'loaders': [ ('django.template.loaders.cached.Loader', [ 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', 'your_app.template_loaders.SpecificAppTemplateLoader', ]), ], }, }, ]
..
A simple jQuery javascript that collapses all stacked inline rows for better handling of large inline fieldsets. It also adds "Show"/"Hide"-buttons for showing/hiding each row, which could be customized and styled using css. **Usage (see below for example):** Include the javascript on your admin page, together with jQuery, and it'll automatically affect all stacked inlines. **Works with** Django 3.1.4 (Might work with other versions with or without adjustments, but not tested) **Use example:** *admin.py:* class DateInline(admin.StackedInline): model = Date extra = 10 class EventAdmin(admin.ModelAdmin): inlines = [DateInline] class Media: js = ['js/collapsed-stacked-inlines.js'] admin.site.register(Event, EventAdmin)
Automatically setup raw_id_fields ForeignKey & OneToOneField
Getting started with crispy forms
A minimally invasive Select widget that looks and acts like a disabled select input, but still submits with the form. It works by rendering the form as disabled, and supplements it's output with a hidden input field with the same name and value. Tested in Django 3.0, probably works in Django 1.11+
This example below to setup default language code as `id` (Indonesian).
added template tag `{% load country2flag %}` and add `{% flagcss%}` to the html header tag usage: `{{ flag_code_string|country }}`
Read the image url as base64 in django, this snippet usefull if you using the `django-easy-pdf` to solve this issue https://github.com/nigma/django-easy-pdf/issues/53 Usage example: ``` <img src="{{ profile.photo.url|read_image_as_base64 }}"> ```
Django zip longest templatetags to handle more than 3 arguments.
I separate this in two files, like this: export_excel.py and actions.py I tried to treat all possible forms of information that may appear in admin, such as properties, functions and normal fields, always getting the column name verbose_name or short_description depending on the case.
Templatetags function to convert the number into numberize method. It usefull to numberize the visitors, users, or other cases.
This snippet shows how to add a `url` field to your API objects, which will then show up as an object in your JSON output. As parameters, you can specify: - `urls`: A list of strings that exist on your URLMan class - `attribute`: The name of the URLMan class on your model, defaults to `"urls"` - `full`: If the full URLs including schema and hostname should be supplied, defaults to `True`
function to parse the string text into json format
3110 snippets posted so far.