djangosnippets.org: Latest snippetshttps://djangosnippets.org/snippets/2024-01-12T11:36:24.491950-06:00Template tag - list punctuation for a list of items
2024-01-12T11:36:24.491950-06:00shapiromatronhttps://djangosnippets.org/snippets/10952/<p>If you have multiple items in a list and want them to be displayed as human readable list of items, this will add the proper punctuation to generate the text. You'll need to provide a conjugation to the end of the list like "or" or "and"; it defaults to "or". …</p>
Freely redistributableJSONRequestMiddleware adds a .json() method to your HttpRequests
2024-01-05T14:28:02.916197-06:00cdcarterhttps://djangosnippets.org/snippets/10951/<p>add JSONRequestMiddleware to your enabled middleware in Django settings. Now, in your view functions, you can call request.json() to get a parsed json body! json is consumed lazily, and cached.</p>
Freely redistributableSerializer factory with Django Rest Framework
2023-06-12T08:34:53.107213-05:00juliohttps://djangosnippets.org/snippets/10950/<p>Creates a model serializer class on the fly, just taking the model (class) as its argument.</p>
<p>My use case: When importing data from spreadsheets, the DRF serializers are an easy way to create model instances from a dictionary. This function saves me from creating a custom serializer each time I …</p>
Freely redistributableImage compression before saving the new model / work with JPG, PNG
2023-05-24T14:14:07.813738-05:00Schleidenshttps://djangosnippets.org/snippets/10949/<p>Don't forget to replace "self.image" by your image field name from your model ex ( self.cover )
replace Product by your model name</p>
<p>works pretty well :)</p>
Freely redistributableHelp text hyperlinks
2023-04-28T08:59:04.718136-05:00sa2812https://djangosnippets.org/snippets/10948/<p>Sometimes a plain-text help-text isn't sufficient, and it's handy to be able to add links to pages, documentation or external websites.</p>
<p>This javascript snippet can be added to your page, in combination with adding a class to your help text in your template. This assumes you're using jQuery on your …</p>
Freely redistributableDjango Collapsed Stacked Inlines
2023-02-24T04:31:40.784315-06:00applecathttps://djangosnippets.org/snippets/10947/<p>A simple jQuery javascript that collapses all stacked inline rows for better handling of large inline fieldsets.</p>
<p>It also adds "Show"/"Hide"-buttons for showing/hiding each row, which could be customized and styled using css.</p>
<p><strong>Usage (see below for example):</strong></p>
<p>Include the javascript on your admin page, together with jQuery, and it'll …</p>
Freely redistributableStuff
2023-02-21T04:39:29.753798-06:00NixonDashhttps://djangosnippets.org/snippets/10946/<p>Stuff</p>
Freely redistributableAdd custom fields to the built-in Group model
2022-12-19T11:51:50.631290-06:00jmoppelhttps://djangosnippets.org/snippets/10945/<p>Add fields and extend Django's built-in <code>Group</code> model using a <code>OneToOneField</code> (i.e. a profile model). In this example, we add a <code>UUIDField</code>. Whenever a new group is created, we automatically (via signals) create a corresponding <code>Role</code> record referencing the newly created group. Whenever a Group is deleted, the corresponding …</p>
Freely redistributableMonth / Year SelectDateWidget based on django SelectDateWidget
2022-09-07T07:45:58.340688-05:00pierrebenhttps://djangosnippets.org/snippets/10943/<p>A more simple version of <a href="https://djangosnippets.org/snippets/1688/">https://djangosnippets.org/snippets/1688/</a>, inheriting from <code>SelectDateWidget</code>, overriding only the necessarily. </p>
<p><strong>Usage example:</strong></p>
<p><strong>In models.py:</strong></p>
<pre><code>from django.db import models
from django.utils.translation import gettext_lazy as _
class MyModel(models.Model):
start = models.DateField(
_("Start date"),
)
end = models.DateField(
_("End date"),
)
class Meta:
verbose_name = _("My model")
</code></pre>
<p><strong>In …</strong></p>
Freely redistributablePython Django CRUD Example Tutorial
2022-08-23T00:43:18.005339-05:00tuts_stationhttps://djangosnippets.org/snippets/10942/<p>Hey Friends,</p>
<p>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.</p>
<p>Read more...</p>
<p><a href="https://tuts-station.com/python-django-crud-example-tutorial.html">https://tuts-station.com/python-django-crud-example-tutorial.html</a></p>
Freely redistributableBrowser-native date input field
2022-07-09T16:31:52.022162-05:00kyttahttps://djangosnippets.org/snippets/10941/<p>Most modern browsers support the new <code><input type="date"></code>, which allows inputting date using a browser-native date picker with built-in validation. This form widget utilizes this feature by setting the input type to "date" and by changing the value formatting as it should be in the ISO format.</p>
<p>See more …</p>
Freely redistributableGenerate and render HTML Table
2022-06-30T11:07:18.336325-05:00LLyaudethttps://djangosnippets.org/snippets/10940/<p>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.</p>
Freely redistributableMy firs Snippets
2022-06-27T02:24:50.120730-05:00GutemaGhttps://djangosnippets.org/snippets/10939/<p>nothing</p>
Freely redistributableFileField having auto upload_to path
2022-05-20T22:49:25.371541-05:00junaidmgithubhttps://djangosnippets.org/snippets/10938/<p>FileField having auto upload_to path</p>
Freely redistributableLazyPrimaryKeyRelatedField
2022-05-13T12:29:27.958382-05:00LLyaudethttps://djangosnippets.org/snippets/10936/<p>When you change dynamicaly the objects manager on your Model class, you may want to have serializers take it into account.</p>
Freely redistributable