Saturday, December 9, 2017

Django Building a blog | Designing blog data Schema

Below is for Ubuntu.
  1. source djangoTestEnv/bin/activate
  2. cd Desktop
  3. django-admin startproject blogSite
  4. cd blogSite
  5. python manage.py startapp myBlog
  6. Go to blogSite/blogSite/settings.py and add 'myBlog' in INSTALLED_APPS section. It should look similar to below
    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'myBlog',
    ]
  7. Open blogSite/myBlog/models.py and paste content in this file
  8. Since models.py is modified, we need to sync DB (migrate) to it. To do this, execute below commands
    cd blogSite (project root folder)
    python manage.py makemigrations myBlog

    output looks similar to below:
    Migrations for 'myBlog':
      myBlog/migrations/0001_initial.py
        - Create model Post

    This means Django just created   myBlog/migrations/0001_initial.py referring to our code in models.py. You can open this file and see how the migration looks like. 
  9. Execute below command to check SQL commands that Django executes
    python manage.py sqlmigrate myBlog 0001
  10. Apply migrations
    python manae.py migrate
  11. For any change in models, we need to apply migrations again just like above.






If you enjoyed this post, make sure you subscribe to my RSS feed! Comments are encouraged

Friday, December 1, 2017

Django Learn Series | Fields


Field Types:
  1. Numeric Data
    1. IntegerField 
    2. DecimalField
  2. Textual Data
    1. CharField
      • Requires max_length attribute
    2. TextField
      • Doesn't require max_length attribute
    3. EmailField
    4. URLField
  3. File Data
    1. FileField
      • Example: filename.docx
    2. ImageField
      • Example: abc.jpg
  4. Miscellaneous Data
    1. BooleanField
    2. DateTimeField
This link provides detailed info about field arguments and field types.

Django Learn Series| Settings



  1. settings.py is global to all apps in a django project.
  2. Django documentation in this link provides good overview of the settings.
  3. This link provides more detailed info of these settings
  4. Settings those needed change for first time.
    • INSTALLED_APPS
    • TEMPLATES
    • STATICFILES_DIRS
  5. Settings those might needed change.
    • DEBUG
      • Set to true by default, but is best set to false when your web project is deployed. When DEBUG is true, any stack traces are shown in the webpage, which is helpful for development but is a security risk when the side is publicly available.
    • DATABASES
      • We're using the built in default database called SQLite, but if you want to use a production ready database such as PostgreSQL or MYSQL, You'll need to change the engine and name entries in the DATABASES setting and in production, you'll need to set the user and password entries for authentication




Thursday, November 30, 2017

Django Learn Series | Creating a Django App


  1. cd Desktop/DjangoPractice/firstdjango
  2. python manage.py startapp firstapp
  3. Files inside firstapp folder are below
    1. models.py -- DB interaction
    2. admin.py -- admin interface
    3. views.py -- App's logic and URL request / response
    4. tests.py -- Automated tests 
    5. migrations folder -- auto generated. Migration files about DB tables changes for the app

Django Learn Series | Creating a Django project



  1. source djangoTestEnv/bin/activate
  2. Create a folder like DjangoPractice on Desktop
  3. cd Desktop/DjangoPractice
  4. django-admin startproject firstdjango
    • Auto creates  a folder named firstdjango and required files in it
    • Subfolder named firstdjango inside firstdjango will have 
      • init.py
      • settings.py
        • Configures Django
      • urls.py
        • Routes requests based on URL
      • wsgi.py
        • provides a hook for webservers
        • WSGI is the Web Server Gateway Interface. It is a specification that describes how a web server communicates with web applications, and how web applications can be chained together to process one request.
        • WSGI is a Python standard described in detail in PEP 3333.
    • main folder firstdjango will have manage.py
    • manage.py runs commands related to firstdjango
  5. cd firstdjango
  6. python manage.py
    • To check list of available command
  7. python manage.py runserver
    • To start the webserver

Django Learn Series | Installation


On Ubuntu Machine, use below steps.

  1. sudo -H pip install virtualenv
    • Using pip and installing virtualenv (recommended) instead of global installation
  2. virtualenv -p python djangoTestEnv
    • djangoTestEnv is sample name of virtual environment
  3. source djangoTestEnv/bin/activate
    • Activating djangoTestEnv
  4. pip install django
    • Installing django in djangoTestEnv
  5. pip freeze
    • This is to check installed packages in that  djangoTestEnv
  6. django-admin --version
    • This is to check the version of django installed in djangoTestEnv

Monday, September 18, 2017

[How To] Convert Qt Designer file.py to Python Code


Assuming input.ui is the file created in Qt Designer, output.py is the python code file name,

  1. open Terminal and cd to input.ui folder.
  2. Type pyuic4 -x input.ui -o output.py and hit Enter
  3. output.py gets created in same folder and run it from Python to get the UI window.





If you enjoyed this post, make sure you subscribe to my RSS feed! Comments are encouraged

[How To] Install PyQt4 and Qt Designer for Python 2


For Ubuntu:

Below is the command to install  PyQt4 and Qt Designer for Python 2

sudo apt-get install pyqt4-dev-tools qt4-designer







If you enjoyed this post, make sure you subscribe to my RSS feed! Comments are encouraged