<?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 Omar Aamir on Medium]]></title>
        <description><![CDATA[Stories by Omar Aamir on Medium]]></description>
        <link>https://medium.com/@omaraamir19966?source=rss-d388244c0f7b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5bRGQs_qAGQeEe9xeFeYFw.jpeg</url>
            <title>Stories by Omar Aamir on Medium</title>
            <link>https://medium.com/@omaraamir19966?source=rss-d388244c0f7b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 13:10:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@omaraamir19966/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[How i got hooked on programming!]]></title>
            <link>https://medium.com/@omaraamir19966/how-i-got-hooked-on-programming-bd6d76a54228?source=rss-d388244c0f7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd6d76a54228</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[problem-solving]]></category>
            <dc:creator><![CDATA[Omar Aamir]]></dc:creator>
            <pubDate>Thu, 27 Jun 2019 12:51:58 GMT</pubDate>
            <atom:updated>2019-06-30T06:50:51.642Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I got hooked on programming!</h3><p>Getting admission in one of the most prestigious Computer Science universities in Pakistan was an achievement in itself however the joy quickly turned to despair when I was faced with some programming problems since I didn’t have any computer science background. Moreover the quick responses of the students having a CS background rubbed salt in the wound. The first three weeks were especially difficult since it felt like I was being left far behind the other students and that this field was not my cup of tea. Then came the day that changed my perspective forever.</p><p>We were given a problem to print a diamond with “*” based on the size given by the user. This lab was like any other lab with me just staring at the problem and hoping that something would pop up into my mind that would solve the problem but nothing. Then another student who had solved the problem showed me the demo and I was really impressed by it. At the moment I thought to myself that if he could solve it WHY NOT ME?</p><p>I went home, fired up my laptop and fully determined tackled the problem again. The statement seemed so simple “Given the size, print a diamond with ‘*’” yet I was having the hardest time converting it into code. After about two hours of logic building, mapping, writing and deleting code my inner voice started to yell “Just copy the code from stackoverflow” after all that is what developers do, isn’t it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yLo38LG29lXTZo5iSIno5Q.jpeg" /></figure><p>Ever faced a problem you couldn’t get your mind around? Frustrating isn’t it? When the code keeps on failing the frustration takes over and in that moment it seems so easy to call it quits and look for an online solution. That was not an option for me as it meant that I concede defeat and I would keep running away from complex problems all my life. I took a small break and rebooted my mind. After that I started looking at the problem from different angles. Each time the code would crash however with each crash it felt as if I was coming closer and closer to the solution. After about 8 hours and about hundreds of crashes it finally ran. I input the size of the diamond and there it appeared right before my very eyes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*AKwcsTRk0nphQVz2lf9Nag.png" /></figure><p>The moment was overwhelming and that was when I got hooked on problem solving. It was just two while loops however the struggle it took to get there made all the difference and it taught me that if you can’t tackle the problem head on, tackle it from the side. There are always multiple solutions to the same problem, I learned that the hard way.</p><p>After that I never ran away from a challenge and the more time it took in solving a problem the more it matured me as a programmer. I started competing in online competitions and solving online challenges, each challenge making me a better programmer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Op6uv6772mqCICoeTyGiuw.png" /></figure><p>From solving a two loop problem to Graduating a Silver Medalist, being a Gold Python Programmer and Problem Solver on hackerrank.com, working as a Full Stack Developer at an international software house it was a tough yet fulfilling road, however facing that SIMPLE PROBLEM helped me face all the problems in the coming years. The lesson I learned was</p><p>If you run away this time, when will you actually face it? And that changed my life.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd6d76a54228" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image Handling with Django]]></title>
            <link>https://medium.com/@omaraamir19966/image-handling-with-django-de4f85a0e907?source=rss-d388244c0f7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/de4f85a0e907</guid>
            <category><![CDATA[image]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Omar Aamir]]></dc:creator>
            <pubDate>Sat, 01 Jun 2019 12:57:35 GMT</pubDate>
            <atom:updated>2019-06-01T13:01:23.751Z</atom:updated>
            <content:encoded><![CDATA[<p>Django being a back-end development framework its safe to assume the the data would be coming from somewhere else that will be handled by Django. Whether it be a mobile application or a web application it can use Djangos REST Apis to handle the data. Passing text and numerical fields is a straight forward process however there is hardly an application that doesn’t incorporate image handling. A most trivial use case would be to handle the profile picture of the user, something which every application handles.</p><p>In this article i’ll be explaining one of many methods of handling image with Django. The ease and simplicity of this method is what makes it usable in almost all cases.</p><h3>Base 64 Encoding Strategy:</h3><p>Base 64 encoding scheme is a technique of converting binary data to ASCII <strong>string format</strong>. All font end applications in whatever framework you use will have methods for base 64 encoding. This strategy comprises of the following steps</p><blockquote>Encode the image as a base 64 string from your front end application.</blockquote><blockquote>Pass the image as a string to your Django web api.</blockquote><blockquote>Decode the string to form the original image.</blockquote><h3><strong>Decoding Image and saving it in a Database</strong></h3><p>Once you extract the image string from your payload you can decode it into an image file using the following function.</p><pre>import base64<br>def base64_to_image(base64_string):<br>    format, imgstr = base64_string.split(&#39;;base64,&#39;)<br>    ext = format.split(&#39;/&#39;)[-1]<br>    return ContentFile(base64.b64decode(imgstr), name=uuid4().hex + &quot;.&quot; + ext)</pre><p>In your model.py file you will specify the profile picture column as an ImageField as follows</p><pre>class User(AbstractUser):<br>    profile_picture = models.ImageField(null=True, default=None, blank=True)<br></pre><p>You can then assign the image returned from the <strong>base64_to_image(base64_string)</strong> to the profile_picture field.</p><pre>#new_user being a User object<br>new_user.profile_picture = base64_to_two_images(profile_picture_str)<br>new_user.save()</pre><p>Once the user object is saved the image will be saved in the media folder and the url of the image will be saved in the database column.</p><p>Hence with this simple technique you can handle images in your own web app.</p><p>If the article was helpful leave a like. Stay tuned for more articles on Django.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de4f85a0e907" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Model Forms in Django]]></title>
            <link>https://medium.com/@omaraamir19966/model-forms-in-django-8bd1cd0cf952?source=rss-d388244c0f7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bd1cd0cf952</guid>
            <category><![CDATA[modelform]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Omar Aamir]]></dc:creator>
            <pubDate>Fri, 22 Feb 2019 08:28:04 GMT</pubDate>
            <atom:updated>2019-02-22T08:28:04.312Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*Rpy8tXBgVgIt45nbQeSg_A.png" /></figure><p>With some experience in the web development domain, we are all familiar with the request method. The data is sent to the controller layer in the form of parameters &lt;key, value&gt; pairs, where it is extracted on the basis of keys and is stored in the database in the form of objects. Django minimizes this process with a concept called Model Forms.</p><h4>Working of Model Forms</h4><p>Down in its core a model form is a class in which the user specifies the fields that are expected from the front end request. When the request is sent to the controller , Django automatically populates the form class with the corresponding request data and returns the ready made object for ones usage. That’s all!</p><h3>Integrating Model Forms in Django Project</h3><p>In this example I will be demonstrating the integration of a simple user signup model form.</p><h4>Step 1: Create forms.py class</h4><p>In your app create a file named forms.py where you will be developing all the model form classes.</p><h4>Step 2: Create Model Form Class</h4><p>Now create the model form class as shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*qlpcu1mUgjKewfI6-TBnDg.png" /></figure><p>Here the username, email and password fields are default in the Django framework. We also require the mobile number of the user hence we have created a new field.<strong> There is no limit to the number of fields that can be defined in a model form</strong>.</p><p><strong>Note:</strong> If for a particular field you are not sure whether the data will be available or not in every request you can mark the field as not required by adding <strong>required=False</strong> in the following way</p><pre>mobile_number = forms.CharField(widget=forms.TextInput, required=False)</pre><h4>Step 3: Sync the request call</h4><p>In the request call that is going to be sent to the controller make sure that the name if the input field corresponds to the name specified in the model form.</p><pre>&lt;input id=&quot;signup_mobile_number&quot; name=&quot;mobile_number&quot; type=&quot;number&quot;<br>       required&gt;</pre><p>Here the <strong>name=mobile_number </strong>in the input tag corresponds to the name specified in the model form class.</p><h4>Step 4: Populate the form in Views.py</h4><p>When handling the request in the views.py all you have to do is pass the request to the model form class and it’ll automatically populate the object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*rq8-1qHas_fHzGQxhaXMSg.png" /></figure><p>You can then save the object or use it as you like.</p><p>Now you know how easy request handle becomes using Django’s Model Forms.</p><p>If the article was helpful leave a like. Stay tuned for more articles on Django.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bd1cd0cf952" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connect DJango with MySQL Database]]></title>
            <link>https://medium.com/@omaraamir19966/connect-django-with-mysql-database-f946d0f6f9e3?source=rss-d388244c0f7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f946d0f6f9e3</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[mysql-workbench]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[mysqlclient]]></category>
            <dc:creator><![CDATA[Omar Aamir]]></dc:creator>
            <pubDate>Sun, 10 Feb 2019 15:33:02 GMT</pubDate>
            <atom:updated>2019-02-10T15:33:02.281Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*WfU7hBsrnvF3X_mT0_kVTg.png" /></figure><p>Out of the box Django comes with sqlite database embedded within the project. Minimum amount of configurations and the ease of data storage and retrieval from sqlite is suitable for web apps on small scale, however for large scale web apps sqlite is going to cause performance issues. In order to avoid performance issues the first step is to select a suitable database able to cater hundreds or even thousands of simultaneous hits. MySQL database can be used for this purpose.</p><p>In this article i’ll follow you though all the necessary configurations required to connect Django with MySQL database.</p><h3><strong>Setting up MySQL Database</strong></h3><h4><strong>Step 1: Create new schema</strong></h4><p>Open the MySQL Workbench and create a new schema by clicking the <em>create new schema in the connected server </em>option.</p><p>Select a suitable schema/database name and press apply. This will create the schema and it will appear in the <em>SCHEMAS </em>section of the MySQL workbench.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*V_d-lYwHv6vxA2CqGFMGXQ.png" /></figure><p>In our case the schema name is <em>djangodatabase.</em></p><h4>Step 2: Create authentication user for the schema</h4><p>Once the schema is ready create an authentication user and grant privileges to this user.</p><p>Create the user by running the following query</p><blockquote><strong>create user dbadmin identified by ‘12345’;</strong></blockquote><p>Here dbadmin is the username and 12345 is the password.</p><p>Grant the privileges by running the following query</p><blockquote><strong>grant all on djangodatabase.* to ‘dbadmin’@’%’;</strong></blockquote><p>Here djangodatabase is the schema/database name. “.*” represents that all privileges are being granted and dbadmin is the user to whom the privileges are being granted.</p><p>In order to load the newly granted privileges to the user run the following query</p><blockquote><strong>flush privileges;</strong></blockquote><p>This is all for the MySQL configuration part. Now lets move towards the Django project.</p><h3><strong>Setting up Django Project</strong></h3><h4><strong>Step 1: Installing MySQL Client</strong></h4><p>You can install MySQL client directly through pip using the command</p><blockquote><strong>pip install mysqlclient</strong></blockquote><p>If MySQL client gets installed that’s great, however this command gives an error on most systems. I’m going to show you an alternative method of installing MySQL client.</p><p>Depending on the python version download the suitable mysqlclient wheel file from the following website.</p><p><a href="https://www.lfd.uci.edu/~gohlke/pythonlibs/">Archived: Python Extension Packages for Windows - Christoph Gohlke</a></p><p>Place the file in the root directory of the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*kc1vcDEWVYQcUXLX1VwEiw.png" /></figure><p>In the same directory open the command prompt and run the following command.</p><blockquote><strong>pip install mysqlclient-1.3.13-cp37-cp37m-win32.whl</strong></blockquote><p>Here the name of the wheel file will change depending on your version of Python. After the command executes MySQL client will be installed on your system.</p><h4><strong>Step 2: Updating the Connect String</strong></h4><p>Open the settings.py file of the Django project. There will be database connection string in the file which will look something like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*-nR2byUXMXcL7LOjmZj8Iw.png" /></figure><p>Update the connection string.</p><pre>DATABASES = {<br>    &#39;default&#39;: {<br>        &#39;ENGINE&#39;: &#39;django.db.backends.mysql&#39;,<br>        &#39;NAME&#39;: &#39;djangodatabase&#39;,<br>        &#39;USER&#39;: &#39;dbadmin&#39;,<br>        &#39;PASSWORD&#39;: &#39;12345&#39;,<br>        &#39;HOST&#39;: &#39;localhost&#39;,<br>        &#39;PORT&#39;: &#39;3306&#39;,<br>    }<br>}</pre><p>Here the name is the scheme/database name, USER is the auth user and PASSWORD is the password for the auth user. ENGINE, HOST and PORT can be left at default settings.</p><h4><strong>Step 3: Make Migrations</strong></h4><p>Now run the command</p><blockquote><strong>python manage.py migrate</strong></blockquote><p>This will migrate all the default Django tables to your MySQL schema.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*bKG5d3TwkYj6uGlf1qonzQ.png" /></figure><p>Now any changes made to the model files will be reflected in the MySQL schema upon migration.</p><p>This is how you can connect Django web app with MySQL database is just a few simple steps.</p><p>If the article was helpful leave a like. Stay tuned for more articles on Django.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f946d0f6f9e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>