<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>django on Jaaved Ali Khan</title><link>https://jaaved.netlify.app/tags/django/</link><description>Recent content in django on Jaaved Ali Khan</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 11 Feb 2024 21:01:19 +0300</lastBuildDate><atom:link href="https://jaaved.netlify.app/tags/django/index.xml" rel="self" type="application/rss+xml"/><item><title>Wagtail</title><link>https://jaaved.netlify.app/notes/202103051807-wagtail/</link><pubDate>Sun, 11 Feb 2024 21:01:19 +0300</pubDate><guid>https://jaaved.netlify.app/notes/202103051807-wagtail/</guid><description>CMS # tags CMS, Django https://wagtail.org/ features Release schedule and LTS versions
Creating Project # Getting started tutorial
Commands # When wagtail project&amp;rsquo;s root dir is not created wagtail start name_of_project
When directory is already created wagtail start site_name project_root_dir_name wagtail start mysite project_root_dir_name
Project structure # Wagtail Apps # https://wagtail.org/packages/
wagtail-speech # Text to Speech https://github.com/moorinl/wagtail-speech
wagtail-2fa # https://pypi.org/project/wagtail-2fa/
wagtail-django-recaptcha # https://pypi.org/project/wagtail-django-recaptcha/
Moving data from development environment to production # Worked in 4.</description></item><item><title>FileField and FieldFile</title><link>https://jaaved.netlify.app/notes/202104051302-filefield_and_fieldfile/</link><pubDate>Wed, 20 Dec 2023 15:51:04 +0300</pubDate><guid>https://jaaved.netlify.app/notes/202104051302-filefield_and_fieldfile/</guid><description>Django Modal FileField # tags: Django ref When you access a FileField on a model, you are given an instance of FieldFile as a proxy for accessing the underlying file.
The API of FileField mirrors that of File (File Object in Django), with one key difference: The object wrapped by the class is not necessarily a wrapper around Python’s built-in file object. Instead, it is a wrapper around the result of the Storage.</description></item><item><title>uWSGI</title><link>https://jaaved.netlify.app/notes/202106151600-uwsgi/</link><pubDate>Mon, 21 Aug 2023 18:09:09 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202106151600-uwsgi/</guid><description>Server # tag Python, Python Apps Python server used for serving Django web requests at ICTC Solution Delivery
Commands # Restart service uwsgi-emperor status service uwsgi-emperor restart Installation # Emperor # - name: Install uWSGI emperor apt: name=uwsgi-emperor state=present - name: Configure uWSGI emperor template: src: emperor.ini.j2 dest: /etc/uwsgi-emperor/emperor.ini owner: root group: root mode: 0644 notify: Restart uWSGI Emperor - name: Create log directory file: path: /var/log/uwsgi/vassals state: directory owner: root group: root notify: Restart uWSGI Emperor - name: Enable app server configuration (uWSGI emperor) template: src: uwsgi.</description></item><item><title>File Object in Django</title><link>https://jaaved.netlify.app/notes/202104051204-file_object_in_django/</link><pubDate>Tue, 15 Aug 2023 21:43:56 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202104051204-file_object_in_django/</guid><description>Summary suspendedfc # ref The File class is a thin wrapper around a Python file object () with some Django-specific additions. Internally, Django uses this class when it needs to represent a file. source
from django.core.files.base import File stream = BytesIO() # stream or file like object pdf_writer.write(stream) page_obj.pdf.save(name=f&amp;#34;page_num.pdf&amp;#34;, content=File(stream)) File class # source
The File class is a thin wrapper around a Python file object with some Django-specific additions.</description></item><item><title>CSRF protection (in Django)</title><link>https://jaaved.netlify.app/notes/csrf_protection--20210912-091731/</link><pubDate>Mon, 10 Jul 2023 14:22:57 +0400</pubDate><guid>https://jaaved.netlify.app/notes/csrf_protection--20210912-091731/</guid><description>Summary # The CSRF middleware and template tag provides easy-to-use protection against .
ref # https://docs.djangoproject.com/en/3.2/ref/csrf/
Protection fc # position ease box interval due front 2.5 0 0 2021-09-12T07:15:09Z The first defense against CSRF attacks is to ensure that GET requests (and other ‘safe’ methods, as defined by RFC 7231#section-4.2.1) are side effect free. Requests via ‘unsafe’ methods, such as POST, PUT, and DELETE, can then be protected by following the steps below.</description></item><item><title>Django Templates</title><link>https://jaaved.netlify.app/notes/202103051805-django_templates/</link><pubDate>Sat, 14 Jan 2023 20:23:06 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202103051805-django_templates/</guid><description> Summary #</description></item><item><title>InMemoryUploadedFile</title><link>https://jaaved.netlify.app/notes/202104061207-inmemoryuploadedfile/</link><pubDate>Sat, 14 Jan 2023 20:18:04 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202104061207-inmemoryuploadedfile/</guid><description>Summary # file_object = request.FILES[&amp;ldquo;uploadedfile&amp;rdquo;]
file_object is the instance of InMemoryUploadedFile. ref: link
Details # They are used to store submitted files through forms in memory(RAM).</description></item><item><title>Date Conversion from Django Template to JavaScript</title><link>https://jaaved.netlify.app/notes/date_conversion_from_django_template_to_javascript--20211222-140535/</link><pubDate>Sat, 14 Jan 2023 20:15:05 +0400</pubDate><guid>https://jaaved.netlify.app/notes/date_conversion_from_django_template_to_javascript--20211222-140535/</guid><description>In project there was a requirement to use
&amp;lt;td&amp;gt; object.time_stamp.isoformat &amp;lt;/td&amp;gt; $.fn.dataTable.ext.search.push( function(settings, data, dataIndex) var min = minDate.val(); var max = maxDate.val(); let dateTime = data[1]; // here !!!!!!!!!!!!! var date = new Date(dateTime); if ( (min === null &amp;amp;&amp;amp; max === null) || (min === null &amp;amp;&amp;amp; date &amp;lt;= max) || (min &amp;lt;= date &amp;amp;&amp;amp; max === null) || (min &amp;lt;= date &amp;amp;&amp;amp; date &amp;lt;= max) ) return true; return false; ); From here: https://stackoverflow.</description></item><item><title>Django Template Tags</title><link>https://jaaved.netlify.app/notes/202103051806-django_template_tags/</link><pubDate>Sat, 14 Jan 2023 20:13:13 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202103051806-django_template_tags/</guid><description/></item><item><title>Django CMS</title><link>https://jaaved.netlify.app/notes/202103051802-django_cms/</link><pubDate>Sat, 14 Jan 2023 20:06:52 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202103051802-django_cms/</guid><description> Summary #</description></item><item><title>Storing Pillow Image object to Django FileField(ImageField)</title><link>https://jaaved.netlify.app/notes/202104061159-storing_pillow_image_object_to_django_filefield_imagefield/</link><pubDate>Mon, 04 Apr 2022 10:31:54 +0300</pubDate><guid>https://jaaved.netlify.app/notes/202104061159-storing_pillow_image_object_to_django_filefield_imagefield/</guid><description>Requirement # Image object in Pillow to File Object in Django and save them as FileField and FieldFile
Methods # From Stackoverflow # ref: link
import StringIO from django.core.files.uploadedfile import InMemoryUploadedFile # Create a file-like object to write thumb data (thumb data previously created # using PIL, and stored in variable &amp;#39;thumb&amp;#39;) thumb_io = StringIO.StringIO() thumb.save(thumb_io, format=&amp;#39;JPEG&amp;#39;) # Create a new Django file-like object to be used in models as ImageField using # InMemoryUploadedFile.</description></item><item><title>Querysets</title><link>https://jaaved.netlify.app/notes/202102252053-querysets/</link><pubDate>Mon, 04 Apr 2022 10:30:54 +0300</pubDate><guid>https://jaaved.netlify.app/notes/202102252053-querysets/</guid><description>Querysets in fc # position ease box interval due front 2.95 5 51.57 2021-10-21T21:35:48Z Custom querysets are configured by the model manager
Calling custom queryset method from manager # class PersonQuerySet(models.QuerySet): def authors(self): return self.filter(role=&amp;#39;A&amp;#39;) def editors(self): return self.filter(role=&amp;#39;E&amp;#39;) class PersonManager(models.Manager): def get_queryset(self): return PersonQuerySet(self.model, using=self._db) def authors(self): # verbose return self.get_queryset().authors() def editors(self): # verbose return self.get_queryset().editors() class Person(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) role = models.CharField(max_length=1, choices=[(&amp;#39;A&amp;#39;, _(&amp;#39;Author&amp;#39;)), (&amp;#39;E&amp;#39;, _(&amp;#39;Editor&amp;#39;))]) people = PersonManager() Creating manager from queryset method # It is shortcut for the above verbose method.</description></item></channel></rss>