<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Oumaima Garci on Medium]]></title>
        <description><![CDATA[Stories by Oumaima Garci on Medium]]></description>
        <link>https://medium.com/@garci.oumaima?source=rss-d75c243ddd67------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5D8AJKHPnM6EX2JN9ck57Q.jpeg</url>
            <title>Stories by Oumaima Garci on Medium</title>
            <link>https://medium.com/@garci.oumaima?source=rss-d75c243ddd67------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 20:06:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@garci.oumaima/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Have you tried Django Signals?]]></title>
            <link>https://medium.com/@garci.oumaima/have-you-tried-django-signals-7efeefb47b6e?source=rss-d75c243ddd67------2</link>
            <guid isPermaLink="false">https://medium.com/p/7efeefb47b6e</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[signal]]></category>
            <dc:creator><![CDATA[Oumaima Garci]]></dc:creator>
            <pubDate>Wed, 29 May 2024 06:02:26 GMT</pubDate>
            <atom:updated>2024-05-29T06:02:26.234Z</atom:updated>
            <content:encoded><![CDATA[<p>Django provides a set of built-in signals, letting us know when Django performs certain operations. So, Signals let a <em>sender</em> notify another <em>receiver</em> that some events have occurred and some actions need to be performed.</p><p>Here are some of the most commonly used built-in signals:</p><ul><li><strong>Model signals:</strong></li></ul><p>– pre_init: whenever you instantiate a Django model, this signal is sent at the beginning of the model’s <strong>__init__()</strong> method.<br>– post_init : same us pre_init but this one is sent when the<strong>__init__()</strong> method finishes.</p><p>– pre_save : sent before a model’s <strong>save()</strong>method is called<strong>.</strong><br>– post_save : sent after a model’s <strong>save()</strong>method is called<strong>.</strong></p><p>– pre_delete : sent before a model’s <strong>delete()</strong>method is called<strong>.</strong><br>– post_delete : sent after a model’s <strong>delete()</strong>method is called<strong>.</strong></p><ul><li><strong>Management signals</strong>; <em>sent by django-admin</em>:</li></ul><p>– pre_migrate : sent before migrations.<br>– post_migrate : Sent at the end of the <strong>migrate</strong><em>(even if no migrations are run) </em>and <strong>flush</strong> commands.</p><ul><li><strong>Request/response signals</strong>: <em>sent by the core framework when processing a request:</em></li></ul><p>– request_started : sent when Django begins processing an HTTP request.<br>– request_finished : sent when Django finishes processing an HTTP request.</p><p>– got_request_exception : sent when Django encounters an exception while processing an HTTP request.</p><p>To understand how signals can be used in real-life Django Applications. Let’s consider a scenario where we want to send a welcome email to new users each time they register for our website.</p><p>If you were to handle sending the welcome email directly in the user registration logic, then the process is tightly integrated with user registration. This means that the recording logic and the email-sending logic would be closely intertwined, making it more difficult to manage or modify each part independently, and this is where Signals come in with two main components: <strong>Sender </strong>and<strong> receiver.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*jVfQTOOsjO72Nyvb_zfQsA.png" /></figure><h4><strong>Let&#39;s build a Signal Receiver function:</strong></h4><ul><li>First, create a new file called <strong><em>signals.py</em></strong> under your app’s root directory.</li><li>Then, create a function <strong><em>send_welcome_email</em></strong> in the <strong><em>signals</em></strong> file; this function will work as a <em>receiver:</em></li></ul><pre>@receiver(post_save, sender=User)<br>def send_welcome_email(sender, instance, created, **kwargs):<br>    if created:<br>        subject = &#39;Welcome to our Website&#39;<br>        message = f&#39;Hello {instance.username}, We would like to thank you for registering at our site.&#39;<br>        from_email = settings.DEFAULT_FROM_EMEAIL<br>        recipient_list = [instance.email]<br>        <br>        send_email(subject, message, from_email, recipient_list)</pre><blockquote>To execute the code in the receiver function for just one Model, define the sender in @receiver decorator.</blockquote><pre>@receiver(pre_save, sender=MyModel)</pre><ul><li>The last step is to connect the signal in the app configuration to tell our app config about the signal we just created; So inside your <strong><em>app.py</em></strong>file, import the signals:</li></ul><pre>from django.apps import AppConfig<br><br><br>class UserManagmentAppConfig(AppConfig):<br>    default_auto_field = &#39;django.db.models.BigAutoField&#39;<br>    name = &#39;user_management&#39;<br><br>    def ready(self):<br>        import user_management.signals</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7efeefb47b6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Atomic Transactions in Django for Reliable Data]]></title>
            <link>https://medium.com/@garci.oumaima/using-atomic-transactions-in-django-for-reliable-data-6c845be7484b?source=rss-d75c243ddd67------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c845be7484b</guid>
            <category><![CDATA[transactions]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[acid]]></category>
            <dc:creator><![CDATA[Oumaima Garci]]></dc:creator>
            <pubDate>Wed, 22 May 2024 06:02:21 GMT</pubDate>
            <atom:updated>2024-05-22T06:02:21.622Z</atom:updated>
            <content:encoded><![CDATA[<p>Django’s default behavior is to run in auto-commit mode. That means that by default :</p><ul><li>Each query like a <strong><em>save</em></strong><em> or </em><strong><em>update</em></strong><em> </em>is immediately committed to the database.</li><li>Each SQL query gets wrapped in its transaction.</li><li>and, a transaction is automatically committed or rolled back.</li></ul><blockquote><strong>Django’s default behavior, </strong>to run in auto-commit mode<strong>, may be problematic;</strong></blockquote><p>If multiple related database operations are performed, there is no guarantee that all of them will succeed or fail together. This can lead to inconsistent states if one operation succeeds but another fails.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*4NBA7R5EdlCTPHxCDaRUSg.png" /></figure><p>So, let’s think of a database transaction as <em>a sequence of one or more SQL operations that are treated as a </em><strong>Unit</strong>. All operations must be executed for the transaction to be successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*aP4vWPYjSbkweReJCulUkg.png" /></figure><p>This idea of transaction has many different theories, one of them being <strong>ACID</strong> properties, which means:</p><blockquote>Ideally, Transaction has <strong><em>four properties</em></strong> commonly known as <strong>ACID</strong>, This is simply a standard set of properties aimed to guarantee database transactions are processed reliably.</blockquote><ol><li><strong><em>Atomicity</em>: </strong>this means that you guarantee that either all of the transactions succeed or none of it does.</li><li><strong><em>Consistency</em></strong>: this ensures that you guarantee that all data will be consistent.</li><li><strong><em>Isolated</em></strong>: to guarantee that all transactions will occur in isolation; No transaction will be affected by any other transaction.</li><li><strong><em>Durable</em></strong>: Once a transaction is committed, it will remain in the system, even though there’s system crash immediately following the transaction.</li></ol><p>To enable atomic transactions for your SQL queries, you only need to open an <strong><em>atomic block </em></strong>and use select_for_update which will lock the rows until the end of the transaction generating a <strong>SELECT ... FOR UPDATE</strong> SQL statement on supported databases.</p><p>So, our example becomes like this;</p><pre>product_obj_1 = Product.objects.select_for_update().get(name=product_name_1)<br>product_obj_2 = Product.objects.select_for_update().get(name=product_name_2)<br><br>with transaction.atomic():<br>    product_obj_1.stock -= z<br>    product_obj_1.save()<br>    product_obj_2.stock += z<br>    product_obj_2.save()</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c845be7484b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django’s Model Inheritance: Simplified]]></title>
            <link>https://python.plainenglish.io/djangos-model-inheritance-simplified-4391debcab2c?source=rss-d75c243ddd67------2</link>
            <guid isPermaLink="false">https://medium.com/p/4391debcab2c</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[inheritance]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[model]]></category>
            <dc:creator><![CDATA[Oumaima Garci]]></dc:creator>
            <pubDate>Wed, 15 May 2024 06:01:44 GMT</pubDate>
            <atom:updated>2024-05-16T01:16:52.249Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>In this article, we will introduce the idea of model inheritance using three options that Django provides: <strong>Abstract models, Multi-table models, </strong>and <strong>Proxy models.</strong></blockquote><h4><strong>Abstract Model using Abstract Base classes (ABC):</strong></h4><ul><li>You use it when you have common information needed for several other models.</li><li>An <strong>ABC</strong> — does not get created in your database.</li><li><strong>ABC</strong>s can be created using the <em>abstract </em>attribute in the model’s <strong>Meta</strong> class.</li><li>Fields are added to other child classes (models).</li><li><em>Example:</em></li></ul><pre>class TimeMixinAbstract(models.Model):<br>    class Meta:<br>        abstract = True<br><br>    created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)</pre><h4>Multi-table inheritance:</h4><ul><li>Vs. <em>abstract model:</em> With <strong>ABC</strong> we have an abstract class that is not included in the actual database. Here, <strong>every model is a model all by itself</strong>.</li><li>Django will build <strong>a One-to-one link </strong>that<strong> </strong>is automatically created behind the scenes to connect two or more models, allowing us to query both tables for the same data.</li><li><em>Example:</em></li></ul><pre>class Carrier(TimeMixinAbstract):<br>    CARRIERS_CHOICES = [<br>        (&quot;gsl&quot;, &quot;GLS&quot;),<br>    ]<br><br>    class Meta:<br>        managed = True<br>        ordering = [&#39;name&#39;]<br>        db_table = &#39;carrier&#39;<br><br>    name = models.CharField(verbose_name=&#39;Name&#39;, max_length=256, default=None, blank=True, null=True)<br>    carrier_company = models.CharField(verbose_name=&#39;Carrier Company Name&#39;, max_length=25, default=&#39;gsl&#39;,<br>                                       choices=CARRIERS_CHOICES, blank=True, null=True)<br>    sender_address = models.CharField(verbose_name=&#39;Sender Address&#39;, max_length=256, default=None, blank=True,<br>                                       null=True)<br>    sender_zipcode = models.CharField(verbose_name=&#39;Sender Zip Code&#39;, max_length=5, default=None, blank=True,<br>                                      null=True)<br>    <br>    def __str__(self):<br>        return self.name<br><br><br>class GSLCarrier(Carrier):<br>    class Meta:<br>        managed = True<br>        ordering = [&#39;username&#39;]<br>        db_table = &#39;gsl_carrier&#39;<br><br>    username = models.CharField(max_length=256, blank=True, null=True)<br>    password = models.CharField(max_length=256, blank=True, null=True)</pre><h4><strong>Proxy Models:</strong></h4><ul><li>Used to change the <em>behavior of a model.</em></li><li>Proxy models operate on <em>the original model</em>.</li><li><em>Example:</em></li></ul><pre><br>class GSLCarrier(Carrier):<br>    class Meta:<br>        managed = True<br>        ordering = [&#39;username&#39;]<br>        db_table = &#39;gsl_carrier&#39;<br><br>    username = models.CharField(max_length=256, blank=True, null=True)<br>    password = models.CharField(max_length=256, blank=True, null=True)<br><br><br>class ProxyCarrier(Carrier):<br>    class Meta:<br>        proxy = True<br>    <br>    def special_delivery_methods(self):<br>        # # Additional functionality specific to the proxy model.<br>        pass<br>    </pre><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a><strong> | </strong><a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://stackademic.com/"><strong>Stackademic</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a><strong> | </strong><a href="https://blog.cubed.run/"><strong>Cubed</strong></a></li><li>Tired of blogging platforms that force you to deal with algorithmic content? Try <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4391debcab2c" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/djangos-model-inheritance-simplified-4391debcab2c">Django’s Model Inheritance: Simplified</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django’s Database Router: Your Guide to Multi-Dimensional Data Management]]></title>
            <link>https://medium.com/django-unleashed/djangos-database-router-your-guide-to-multi-dimensional-data-management-48bd100a8252?source=rss-d75c243ddd67------2</link>
            <guid isPermaLink="false">https://medium.com/p/48bd100a8252</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[medium]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Oumaima Garci]]></dc:creator>
            <pubDate>Wed, 08 May 2024 06:01:42 GMT</pubDate>
            <atom:updated>2024-05-13T00:59:25.162Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine your Django project as a bustling city, with data flowing like traffic on its streets.</p><p>Now, picture the database router as the city planner, strategically directing this traffic to different lanes and highways. Why? Because not all data needs to take the same route! Some might need to zip through for quick access, while others can take a scenic route for analysis.</p><p>By using multiple databases, you’re essentially creating a network of expressways, side streets, and bike lanes tailored to your application’s needs. It’s like giving your data its GPS, ensuring it reaches its destination efficiently, securely, and without getting stuck in a traffic jam.</p><p>So let’s go coding :)</p><p>Traditionally, we have one database, defined in<a href="https://docs.djangoproject.com/en/3.2/ref/settings/#std-setting-DATABASES"><strong>DATABASES</strong></a>settings, for our Django project, so Django knows this database and we’ll send information directly to this database.</p><blockquote>The alias <strong>default </strong>has a special significance. Django uses the database with the alias of <strong>default</strong> when no other database has been selected.</blockquote><pre># # setting.py<br>DATABASES = {<br>    &quot;default&quot;: {<br>        &quot;ENGINE&quot;: &quot;django.db.backends.postgresql&quot;,<br>        &quot;Name&quot;: BASE_DIR / &#39;db.sqlite3&#39;,<br>    }<br>}</pre><p>Now, when we set up multiple databases, Django will have no idea which database to select.</p><p>So the idea here is that we’re going to <em>set up </em><strong><em>a database router</em></strong> and within that router, we’re going to describe what databases are available for Django and our applications to connect to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*H-oY81e6vNkwUxQ6ItZ1Ug.png" /></figure><p>The first step to using more than one database with Django is to tell Django about the database servers you’ll be using. This is done using the <a href="https://docs.djangoproject.com/en/3.2/ref/settings/#std-setting-DATABASES"><strong>DATABASES</strong></a> setting. So, let’s<strong><em> Define our Databases:</em></strong></p><pre>DATABASES = {<br>    &#39;default&#39;: {},<br>    &#39;db_customers&#39;: {<br>        &#39;NAME&#39;: &#39;user_data&#39;,<br>        &#39;ENGINE&#39;: &#39;django.db.backends.mysql&#39;,<br>        &#39;USER&#39;: &#39;mysql_customer&#39;,<br>        &#39;PASSWORD&#39;: &#39;**********&#39;<br>    }<br>}</pre><blockquote>If the concept of a <strong>default</strong> database doesn’t make sense in the context of your project, you need to be careful to always specify the database that you want to use. Django requires that a <strong>default</strong> database entry be defined, but the parameters can be left blank if it will not be used.</blockquote><p>Now, what we need to do is to <strong>create a router</strong> to tell Django that this <strong><em>db_customers</em></strong>exists and that we should use it when we’re building customer database:</p><ol><li>Build a new folder called <strong><em>routers</em></strong> that you can place anywhere because we need to define in the <strong><em>settings.py</em></strong> file where this file is.</li><li>Inside this folder, we create a new file called <strong><em>db_routers .</em></strong></li><li>Define your database router in the <strong><em>settings.py</em></strong> file by adding the router path under <strong><em>DATABASE_ROUTERS</em></strong> :</li></ol><pre># # folder_name.file_name.class_name<br>DATABASE_ROUTERS = [&#39;routers.db_routers.CustomerRouter&#39;]</pre><p>4. Set up <em>a database routing scheme:</em></p><blockquote>A database Router is a Python-Class that provides up to four methods: <strong><em>db_for_read , </em></strong><strong><em>db_for_write , </em></strong><strong><em>allow_relation , </em></strong><strong><em>allow_migrate</em></strong></blockquote><pre>class CustomRouter:<br>    &quot;&quot;&quot;<br>    A router to control all database operations on models in the<br>    customers application.<br>    &quot;&quot;&quot;<br>    route_app_labels = {&#39;customers&#39;}<br><br>    # Attempts to read customers models go to db_customers.<br>    def db_for_read(self, model, **hints):<br>        if model._meta.app_label in self.route_app_labels:<br>            return &#39;db_customers&#39;<br>        return None<br><br>    # Attempts to write customers models go to db_customers.<br>    def db_for_write(self, model, **hints):<br>        if model._meta.app_label in self.route_app_labels:<br>            return &#39;db_customers&#39;<br>        return None<br><br>    # Allow relations if a model in the customers apps is involved.<br>    def allow_relation(self, obj1, obj2, **hints):<br>        if (<br>                obj1._meta.app_label in self.route_app_labels or<br>                obj2._meta.app_label in self.route_app_labels<br>        ):<br>            return True<br>        return None<br><br>    # Make sure the customers app only appear in the &#39;db_customers&#39; database.<br>    def allow_migrate(self, db, app_label, model_name=None, **hints):<br>        if app_label in self.route_app_labels:<br>            return db == &#39;db_customers&#39;<br>        return None</pre><h4>Reminders:</h4><ul><li>To synchronize your databases, you can use <a href="https://docs.djangoproject.com/en/3.2/ref/django-admin/#django-admin-migrate"><strong>migrate</strong></a><strong> </strong>management command by providing the<strong> </strong><a href="https://docs.djangoproject.com/en/3.2/ref/django-admin/#cmdoption-migrate-database"><strong>--database</strong></a> option so you tell Django to synchronize a different database.</li></ul><pre>./manage.py migrate --database=customers</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48bd100a8252" width="1" height="1" alt=""><hr><p><a href="https://medium.com/django-unleashed/djangos-database-router-your-guide-to-multi-dimensional-data-management-48bd100a8252">Django’s Database Router: Your Guide to Multi-Dimensional Data Management</a> was originally published in <a href="https://medium.com/django-unleashed">Django Unleashed</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking Data Integrity: The Essential Guide to Pandera]]></title>
            <link>https://medium.com/@garci.oumaima/unlocking-data-integrity-the-essential-guide-to-pandera-20f6e9b50cf6?source=rss-d75c243ddd67------2</link>
            <guid isPermaLink="false">https://medium.com/p/20f6e9b50cf6</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-validation]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Oumaima Garci]]></dc:creator>
            <pubDate>Wed, 01 May 2024 06:01:42 GMT</pubDate>
            <atom:updated>2024-05-01T06:01:42.486Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Pandera </strong>is an open source project that provides a flexible API to perform <em>data validation on dataframes.</em></p><p>You can install it with pip install pandera</p><p>With <strong>Pandera</strong>, you can :</p><ol><li>Define a <strong>Schema</strong> once and use it to validate different dataframes.</li><li><strong>Check</strong> the types and properties of columns or values.</li><li><strong>Lazy Validate</strong> dataframes.</li></ol><h4>Define Your Schema:</h4><ul><li>Define rules per column.</li><li>Multiple checks can be applied to a column.</li></ul><figure><img alt="Define your schema" src="https://cdn-images-1.medium.com/max/701/0*8UlAX8w1v8gJefR3" /><figcaption>Define your schema</figcaption></figure><h4>Check Types and Properties:</h4><ul><li>Pandera provides its interface for datatypes.</li><li>Pandera columns and indexes accept also native types.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/0*Fg3FRD94hTDmALYo" /></figure><h4>Lazy validate Dataframes:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/0*JITabWn9ZX4LTZnA" /></figure><blockquote>A <em>SchemaErrors</em> exception is raised with a summary of the error counts and failure cases caught by the schema like:</blockquote><ul><li>A <em>column</em> specified in the schema is not present in the dataframe.</li><li>The<em> data type</em> does not match.</li><li>The <a href="https://pandera.readthedocs.io/en/stable/reference/generated/pandera.checks.Check.html#pandera.checks.Check"><em>Check</em></a> specified in one of the columns returns False or a boolean series containing at least one False value.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20f6e9b50cf6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Django Middleware: Elavating Your Web Development Skills]]></title>
            <link>https://medium.com/@garci.oumaima/mastering-django-middleware-elavating-your-web-development-skills-38c4100f49b2?source=rss-d75c243ddd67------2</link>
            <guid isPermaLink="false">https://medium.com/p/38c4100f49b2</guid>
            <category><![CDATA[middleware]]></category>
            <category><![CDATA[advanced]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Oumaima Garci]]></dc:creator>
            <pubDate>Wed, 24 Apr 2024 06:02:04 GMT</pubDate>
            <atom:updated>2024-04-24T06:02:04.981Z</atom:updated>
            <content:encoded><![CDATA[<p>Middleware is a framework of hooks into Django’s request/response processing. It’s a light, low-level <em>“plugin” </em>system for globally altering Django’s input or output.</p><p>So much of this might not make sence to you, but hoppeffuly at the end of this article, you’ll have a better understanding of this description.</p><p>Let’s start by recaping a <strong>typical HTTP response cycle</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*m-1tyaeasXZv9wbhv26teg.png" /><figcaption>Django request/response cycle</figcaption></figure><p>Clients open up a browser, request a web resource so they want to connect to our website which is running with Django.</p><p>They enter the domain name and an HTTP request is created. This Http request will attempt to connect to our web server which handle where this data should go, in this case to our Django application.</p><p>Django needs to match the URL entered by the client to a View, and then processed by our view.</p><p>Now, our view might be connected to a database and a template, and eventually, we send an HTTP response, which might include template information back to our webserver, to sent back to our clients.</p><p>And of course, clients would be able to view or see the web page in their browsers.</p><p>So, let’s think of middleware as applications that run before the view is processed in a Django request/response cycle. So, based on this example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2-CLKyIeqO8AtMg5pBxm5w.png" /></figure><p>The clients will request a web resource, that will be sent to the webserver, and then the webserver will be attached to a Danjgo application, So Django would take that HTTP request through the middlewares; <em>each application in the middleware tha’s specified in the middleware settings</em>, and data will then be proccessed by the View.</p><p>Once the View finished proccessing , it will return an HTTP response, and that data will go through the middleware again.</p><p>To confirm, the request will pass through the middleware<strong> twice.</strong></p><p>Now, <strong>When should I use Middleware?</strong></p><ul><li>Filtering request.</li><li>Inject Data into Requests/Response.</li><li>Performing Logging/Page Analysis.</li></ul><p>This can give you some ideas to use middlewares in your projects. Also, django provides a list of middlewares like:</p><ul><li><strong>Security middleware</strong>: HTTP strict Transport Security, Referrer Policy and SSL Redirect.</li><li><strong>Local middleware</strong>: to enable language selection based on data from the request.</li><li><strong>GZip middleware</strong>: to compress content from browsers that undersand GZip compression, and that can help speed up the delivery of data to the user.</li></ul><p>Now, Let’s build in a demo for a middleware:</p><ol><li>Create a new file called <em>middleware.py </em>in your django app.</li><li>Implement a<strong> python class</strong> called CustomMiddlewareMixin inside this file:</li></ol><pre>class MiddlewareMixin:<br><br>   # # Inform our django app that this is a middleware application <br>   def __init__(self, get_response):<br>        self.get_response = get_response<br><br>    # # Where to perform our actions and that returns a response.<br>    def __call__(self, request):<br><br>        ...<br><br>        response = self.get_response(request)<br><br>        return response</pre><p>3. Place the new middleware at the bottom of list of application middlewares.</p><pre>MIDDLEWARE = [<br>    &#39;django.middleware.security.SecurityMiddleware&#39;,<br>    &#39;django.contrib.sessions.middleware.SessionMiddleware&#39;,<br>    &#39;django.middleware.common.CommonMiddleware&#39;,<br>    &#39;django.middleware.csrf.CsrfViewMiddleware&#39;,<br>    &#39;django.contrib.auth.middleware.AuthenticationMiddleware&#39;,<br>    &#39;django.contrib.messages.middleware.MessageMiddleware&#39;,<br>    &#39;django.middleware.clickjacking.XFrameOptionsMiddleware&#39;,<br>...<br>    # app_name.file_name.class_name<br>    &#39;demo_middleware.middleware.CustomMiddlewareMixin&#39;<br>]</pre><blockquote>Django middleware class has <strong>two required methods</strong> __init__ and __call__, and <strong>optional methods </strong>that execute at different points of the view request/response life-cycle.</blockquote><ol><li><strong>Called during request:</strong></li></ol><ul><li><em>process_request(request)</em></li><li>p<em>rocess_view(request, view_func, view_args, view_kwargs) → Logic executed before a call to view and gives access to the view itself &amp; arguments.</em></li></ul><p><strong>2. Called during response</strong>:</p><ul><li><em>process_exception(request, exception) → only if the view raised an exception.</em></li><li><em>process_template_response(request, response) → only for template responses.</em></li><li><em>process_response(request, response)</em></li></ul><p>and that’s it ! Hope you enjoy reading this article :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38c4100f49b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Pipelined Table Functions in Oracle: Enhancing Data Processing and Performance.]]></title>
            <link>https://medium.com/@garci.oumaima/pipelined-table-functions-527514633b96?source=rss-d75c243ddd67------2</link>
            <guid isPermaLink="false">https://medium.com/p/527514633b96</guid>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Oumaima Garci]]></dc:creator>
            <pubDate>Sat, 20 Apr 2024 13:21:03 GMT</pubDate>
            <atom:updated>2024-04-21T11:06:08.360Z</atom:updated>
            <content:encoded><![CDATA[<p>Pipelined Table functions are Table functions that “<strong>Pipe</strong>” rows back to the calling query as the function produces the data in the desired format and before the function has completed all of its processing, So, we can visualize a large set of data <strong>at immense speed</strong>.</p><p>Normally, when we want to retrieve a set of infomation, we <strong>E</strong>xtract data from the database tables, and then we <strong>T</strong>ransform the data into desired output format to <strong>L</strong>oad it to the client. This <strong>ETL</strong> process consumes huge time if we develop it in a formal way.</p><p>So, Let’s image this situation:</p><ul><li>100,000 rows.</li><li><em>Regular tables funtions </em>build up the whole collection in the memory and then they return the result.</li><li>In the other side, <strong>Pipelined table functions </strong>never hold more than a single row in memory at any time.</li><li>So, <strong>The memory usage between the two methods would be vastly different.</strong></li></ul><p>How we implement a <strong>Pipelined table function?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*T0C5rXA_Ye681BRP" /></figure><ol><li>We create a schema-level nested table type of numbers; <em>array</em>.</li><li>We compile a table function that returns a nested table of that type.</li><li>We will create a pipelined version of that same table function.</li></ol><p><strong>Reminder:</strong></p><ul><li><strong>Pipelined table functions r</strong>eturn sets of data when the next set of data is being processed.</li><li>Add the <strong>PIPELINED</strong> keyword to the function header.</li><li>Use <strong>PIPE ROW </strong>to send the data back to the calling</li><li><em>SELECT</em> statement instead of adding the data to a local collection.</li><li><strong>Return</strong> nothing.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=527514633b96" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real-time Gender Detection YOLOv3]]></title>
            <link>https://medium.com/@garci.oumaima/real-time-gender-detection-yolov3-4db1c9c96e31?source=rss-d75c243ddd67------2</link>
            <guid isPermaLink="false">https://medium.com/p/4db1c9c96e31</guid>
            <category><![CDATA[google-colab]]></category>
            <category><![CDATA[yolov3]]></category>
            <category><![CDATA[darknet]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[gender-recognition]]></category>
            <dc:creator><![CDATA[Oumaima Garci]]></dc:creator>
            <pubDate>Wed, 08 Sep 2021 21:46:28 GMT</pubDate>
            <atom:updated>2021-09-08T21:46:28.300Z</atom:updated>
            <content:encoded><![CDATA[<p>This tutorial covers the real-time gender detection Deep Learning Model (using YOLO<em>v3</em>) in google colab on a <em>custom dataset</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*Jg8S-afwdfUxtP9AOw1t0A.png" /></figure><h3>Welcome!</h3><p>We will show you how to:</p><ul><li>Train a <strong>Yolo v3</strong> model using <strong>Darknet</strong> and Colab <strong>12GB-RAM GPU</strong>.</li><li>Turn Colab notebooks into an effective tool to work on real projects. Dealing with the handicap of a runtime that will <strong>blow up every 12 hours</strong> into the space!</li><li>Working directly from the files on your computer.</li><li>Configure your notebook to install everything you need and start training in about a minute (Tested using 550MB dataset).</li><li>Receive your trained weights directly on your computer during the training. While the notebook is training you can check how it is going using your trained weights in your computer.</li></ul><h4>These are the steps we’ll follow:</h4><ul><li>Prepare custom dataset.</li><li>Configure Google Drive and map as network <em>Drive</em>.</li><li>Some utils to help to do some tasks.</li><li>Configure the pre-requisites on the runtime.</li><li>Explained how to manage your YOLO files on your computer and it will be used transparently from this notebook.</li></ul><blockquote><strong>NOTE:</strong> Cells with an annotation <strong># Not Necessary cell</strong>. Can be removed without having any impact. They are only explanatory content.</blockquote><h3>Without further ado, let’s start!</h3><h4>STEP 0. Prepare your own dataset and configuration files</h4><p>This is a crucial step and the performance of your model depends on the quality of data you collected.</p><ol><li>Search for images and videos related to the problem in your problem domain.</li><li>Making annotations by drawing rectangles, we’ll use <strong>LabelImg</strong> for this task.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*TsV4z95Fv21ozSvbOTVTdA.png" /></figure><p>Before going further let’s take a look at what configuration files you need to have in your local drive <em>darknet</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fd9rgMFtecToVGs5GZwLSA.png" /></figure><p><strong><em>TRICK:</em></strong> You have to be carefully configuring paths on your config files. <em>obj.data</em> file needs to have spaces on the path escaped with “<strong><em>\”</em></strong>.</p><p>Like this: <a href="https://colab.research.google.com/drive/1dCZd4iPYs85PY66dNxlWv5OA7PU2jPsI#"><strong><em>/content/gdrive/My</em></strong></a><strong><em>\ Drive/darknet/train.txt</em></strong>. But, in files <strong><em>train.txt</em></strong> and <strong><em>test.txt</em></strong> does not!</p><h3>Loading files to VM local drive</h3><p>The network speed between Google Drive and Colab VM can have an impact on your training speed accessing your dataset images.</p><ul><li>You can try to use directly the files from Google Drive <em>img/</em> folder.</li></ul><p><em>Depending on your dataset maybe this can be more than good.</em></p><p><em>You don’t have to do anything here. Your </em><strong><em>train.txt</em></strong><em> should have the correct path: </em><a href="https://colab.research.google.com/drive/1dCZd4iPYs85PY66dNxlWv5OA7PU2jPsI#"><strong><em>/content/grdive/My Drive/darknet/img/woman001.jpg</em></strong></a><em>.</em></p><p><em>As said before, don’t use escaped white space for the paths on </em><strong><em>train.txt</em></strong><em> and </em><strong><em>test.txt</em></strong></p><h4>STEP 1. Connect your files to Google Drive</h4><p>In order to have your files on your local computer, you need to install and configure Google Backup and Sync to keep one folder of your Drive synced with a folder on your computer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*B5sFrN-rkl89R1-eM_eYfw.jpeg" /></figure><ol><li>Create a folder on your Google Drive named <strong><em>darknet</em></strong></li><li>Configure the Google Backup and Sync as follows.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*tdfao0CS0jJsMvNhxjLjfg.png" /></figure><p><strong>After this step, you’ll have a folder called <em>darknet</em> on your local computer. This folder is where you will work with files on your computer</strong></p><blockquote><strong>TIP</strong> — We need to have a good performance downloading data from Drive to Colab. Having a lot of files in your Drive root folder can slow down the things quite a bit. It’s a good practice working with Colab to move all your root folder files into a folder</blockquote><h4>STEP 2. Connect the Colab notebook to Google Drive</h4><p>Now we’re gonna map your Google Drive folder. This first step is the only one that will require your manual interaction every time you run your notebook.</p><ul><li>Execute the following cell <em>(Click on the Play button or press CTRL + ENTER)</em> and click on the link to authorize your notebook to access your Google Drive.</li><li>Paste the code Google will give to you and push enter</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G9iRCarQfldUMF95gr5zLg.png" /></figure><h4>STEP 3. Check CUDA release version</h4><p>Nvidia CUDA is pre-installed on Colab notebooks. Now we’ll check the version installed.</p><blockquote><strong>BE AWARE:</strong> Maybe some time from the time I’m writing these lines the CUDA version is upgraded on Colab and you should download another version of the cuDNN in the next step. Now is release 10.0 and we are using cuDNN (cudnn-10.0-linux-x64-v7.5.0.56.tgz) accordingly</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2QC-6npESSHXlFrP6-Araw.png" /></figure><h4>STEP 4. Install cuDNN according to the current CUDA version</h4><p>Now, you need to download cuDNN from Nvidia web site. You’ll need to sign up on the site.</p><ul><li>Download cuDNN from the <a href="https://developer.nvidia.com/cudnn">Nvidia website</a>: Right now, because we have <strong><em>CUDA 10.0</em></strong> preinstalled in Colab runtime, you need to download <a href="https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v7.5.0.56/prod/10.0_20190219/cudnn-10.0-linux-x64-v7.5.0.56.tgz">cuDNN v7.5.0.56 for CUDA v10.0</a> — the file is <em>cudnn-10.0-linux-x64-v7.5.0.56.tgz</em></li><li>On your local computer, create a folder named <strong><em>cuDNN</em></strong> in your local folder <strong><em>darknet</em></strong>. Copy the <strong><em>tgz</em></strong> file there.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*dkDggLWTdG72-3JafIrm4A.png" /></figure><h4>STEP 5. Uploading everything to Google Drive</h4><ol><li>Installing Darknet from <a href="https://github.com/AlexeyAB/darknet/">AlexeyAB’s Darknet repo</a> and Upload it to darknet Folder.</li><li>Upload dataset folder.</li><li>Download Yolo weight from <a href="https://pjreddie.com/darknet/yolo/"><strong>darknet repository</strong></a> and upload it to your drive ( we’re using here darknet53conv.74).</li></ol><p><strong>Great!!</strong> We have all the necessary to start working with Darknet.</p><p><strong>Here comes our first trick to speed up the runtime load time</strong></p><ul><li>Clone and compile the darknet project.</li><li>Copy the compiled version to our Google Drive Folder.</li></ul><p><em>The next time, instead of compiling it again on every runtime load, we’ll copy the compiled version to our VM machine!</em></p><p><em>When compiling the first time, your output last line has to be something like this:</em></p><p>g++ -std=c++11 -Iinclude/ -I3rdparty/stb/include -DOPENCVpkg-config --cflags opencv-DGPU (...)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*CRzlI6OKY48y5ErxBkKcsw.png" /></figure><p><strong><em>Copying the compiled version of Darknet from Drive</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*4JMGiPBYGI-7zxNB95UlSg.png" /></figure><h4>STEP 6. Train your model!</h4><p>When you execute the following command, your model will start training.</p><p>You will have a logline per epoch. On each iteration, you will see how your training is going.</p><blockquote><strong>TRICK: </strong>Darknet copies a backup of your trained weights every 100 iterations. As magic, this file will be synced to your local drive on your computer, as well as the backups darknet do every 1000 iterations, saving it on a separate file.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-oeiR7iQv8zbdh0M7RsDQw.png" /></figure><h3>STEP 7 . Test your model!</h3><p><strong>NOTE:</strong> The following test only will work when the darknet is compiled in the runtime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-BOXPbaB7bp_VWYkmvSngQ.png" /></figure><h3><strong>STEP 8. Evaluate your model!</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IDHDPPHRolbXZL6Th7oWRA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*6Epu9mNq5N4ioWMudq3V2Q.png" /></figure><p><em>Verification commands </em>generate a woman.txt an man.txt files under <a href="https://colab.research.google.com/drive/1dCZd4iPYs85PY66dNxlWv5OA7PU2jPsI#">/darknet/results</a>/</p><p>Where the data format in txt is: <strong>filename confidence x y w h</strong></p><h3>PERFORMANCE TIPS &amp; TRICKS</h3><ul><li><strong>Speed up load times of the runtime:</strong> When everything is checked that works, you can remove cells or comment unnecessary lines of code to make your loading time lower on every run.</li><li><strong>How to keep your notebook alive for more time?:</strong> Keep your browser with your notebook open. If you close your browser, your notebook will reach the middle time and will be removed from Colab cloud Service. (90 minutes)</li><li><strong>Re-run your training after reaching the limitation time for Colab runtimes (12 hours):</strong></li><li>Open a new notebook or reconnect the current one.</li><li>Comment the cell above and uncomment the cell below.</li><li>Execute Run all in the <strong>&gt; menu &gt; Runtime &gt; Run All</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sh15_fCwkfmUG3LdZcx_zg.png" /></figure><h3>TROUBLESHOOTING</h3><p>The main problems you can face if your model throws an error is:</p><ul><li>Images or files not found. Check the <strong>Yolov3 cheat sheet</strong> image above and check that everything is ok.</li><li>If you have configured wrongly your <strong>filters</strong> and <strong>classes</strong> in the <strong>yolov3.cfg</strong>. Check the <strong>Yolov3 sheet</strong> above.</li><li>You can face some out-of-memory or library errors mainly for the lack of some of the pre-requisites. In this case, check the versions of the current libraries installed on your Colab VM. You can find more information in the first steps of this notebook.</li><li><strong>Batch</strong> and <strong>subdivisions</strong> parameters on your <strong>yolov3.cfg</strong> can affect the memory allocation as well. Refer to the original repo <a href="https://colab.research.google.com/drive/1dCZd4iPYs85PY66dNxlWv5OA7PU2jPsI">here</a> for further details.</li></ul><h4><strong>Google colaboratory sheet :</strong></h4><p><a href="https://colab.research.google.com/drive/1dCZd4iPYs85PY66dNxlWv5OA7PU2jPsI?usp=sharing">Google Colaboratory</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4db1c9c96e31" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>