djangosnippets.org: Latest snippets tagged with 'django'https://djangosnippets.org/tags/django/2022-08-23T00:43:18.005339-05:00Python 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 redistributableLog the time taken to execute each DB query
2021-03-24T04:15:55.218642-05:00kennyx46https://djangosnippets.org/snippets/10853/<p>Use this snippet to log the time taken to execute a specific DB query.</p>
Freely redistributableAutomatically setup raw_id_fields ForeignKey & OneToOneField
2020-05-21T08:33:35.511673-05:00agusmakmunhttps://djangosnippets.org/snippets/10813/<p>Automatically setup raw_id_fields ForeignKey & OneToOneField</p>
Freely redistributableDjango Language Middleware
2020-03-08T04:24:53.693829-05:00agusmakmunhttps://djangosnippets.org/snippets/10769/<p>This example below to setup default language code as <code>id</code> (Indonesian).</p>
Freely redistributableRead image url as base64
2020-01-28T21:17:43.951410-06:00agusmakmunhttps://djangosnippets.org/snippets/10763/<p>Read the image url as base64 in django, this snippet usefull if you using the <code>django-easy-pdf</code> to solve this issue https://github.com/nigma/django-easy-pdf/issues/53</p>
<p>Usage example:</p>
<p><code><img src="{{ profile.photo.url|read_image_as_base64 }}"></code></p>
Freely redistributableDjango zip longest templatetags to handle more than 3 arguments.
2019-12-12T01:02:24.472688-06:00agusmakmunhttps://djangosnippets.org/snippets/10718/<p>Django zip longest templatetags to handle more than 3 arguments.</p>
Freely redistributableDjango Standard API Response Middleware for DRF
2019-12-11T08:02:03.303049-06:00agusmakmunhttps://djangosnippets.org/snippets/10717/<p>As you can see, if you using django-rest-framework, you will found many different response format. This middleware to solve all of these problems with Standard API Response.</p>
<p>All HTTP Response status stored into json response, not in HTTP Status (because mobile application, like android can't fetch the response body when …</p>
Freely redistributableAction export django admin to excel exactly as it appears in list-display
2019-10-24T13:42:49.988362-05:00PunisherGuhttps://djangosnippets.org/snippets/10681/<p>I separate this in two files, like this:
export_excel.py and actions.py</p>
<p>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.</p>
Freely redistributablea better Django Slug Unique Generator
2019-10-17T10:14:57.330299-05:00ParsaFakharhttps://djangosnippets.org/snippets/10680/<p>let say the user chooses the name "Elsa Frozen"
now his slug would be "Elsa-Frozen-5"</p>
<p>it means 4 other people have used the same header
now he can go to url: "your website.com/Elsa-Frozen-4" to see other people's Post</p>
Freely redistributableDjango numberize templatetags
2019-09-11T19:38:54.790608-05:00agusmakmunhttps://djangosnippets.org/snippets/10679/<p>Templatetags function to convert the number into numberize method. It usefull to numberize the visitors, users, or other cases.</p>
Freely redistributableparse json string
2019-08-11T17:23:52.066397-05:00agusmakmunhttps://djangosnippets.org/snippets/10676/<p>function to parse the string text into json format</p>
Freely redistributableCalculating Maintainability Index for a whole project
2019-04-18T08:43:18.039984-05:00MrtnBckrhttps://djangosnippets.org/snippets/10665/<p>With this command you can calculate the maintainability index for your whole project. </p>
<p>In your settings you have to add a dictionary called <code>RADON_MI_SETTINGS</code>. It could be like this: </p>
<p><code>python
RADON_MI_SETTINGS = {
'paths': ['projectname'],
'exclude': 'projectname/some_app/some_file.py',
'ignore': 'migrations,tests',
}</code></p>
<p>I had to add following packages:
<code>radon==3.0.1
progress==1.5
plotly==3.7.0 …</code></p>
Freely redistributableDjango nginx sendfile example
2019-04-17T06:53:36.356646-05:00sim1234https://djangosnippets.org/snippets/10664/<p>Use nginx sendfile (X-Accel-Redirect) function to serve files but pass traffic through django. Can be used to serve media files only to logged-in users.</p>
Freely redistributableChoiceField's choices from model
2019-03-28T08:46:47.400767-05:00cansarigolhttps://djangosnippets.org/snippets/10662/<p>I have a product table but don't have a brand table. brands in product.brand as denormalized and I want to choose brands from a select tag.</p>
Freely redistributablespaceless_json
2019-03-04T06:53:58.732628-06:00dkoldyaevhttps://djangosnippets.org/snippets/10661/<p>Now you can format and compress json-data in django template</p>
Freely redistributable