Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Monday, 19 September 2016

// // 1 comment

Django: Difference between BLANK and NULL model attributes

At some point in my experience with django web framework, i have been puzzled as regards the meaning / difference between the above model attributes. Here is a pretty nice explanation for them:
NULL: setting the null attribute of a django model to True allows that particular field to save empty values as null in your database. null is a database terminology that represents a missing value. It is very different from a zero or a space value, it is just the database word for empty.(consult an SQL textbook for more explanation). The null attribute works on the database level and has nothing to do with form validation.The default value is False.
BLANK: django uses your model classes to perform  different abstractions which include automatically creating forms to feed data to your database where needed. setting blank = true allows any of these forms to be left blank. setting it to False makes it a required field hence raises an error on the form when left blank.
As the official docs has it:
Note that this is different than null. null is purely database-related, whereas blank is validation-related. If a field has blank=True, form validation will allow entry of an empty value. If a field has blank=False, the field will be required.
the default value is False.
So when and how do i use blank=True or Null=True?
use blank=True when you want a user to continue his/her action without filling a form, vice versa.
use null=False when you don't want an a null value in your database irrespective how. However, Both attribute can be combined in some cases.
(blank=True, null=False) will raise an integrity error if the field is left blank.(TextField and CharField sends an empty string as value instead).
(blank=False, null=True) forbids the form from being empty but allows a null value in database if set manually through raw sql code or any other means.
I hope this helps.
Read More

Thursday, 7 January 2016

// // 1 comment

Solution to Tcl error: favicon . ico is not defined when setting windows icon in tkinter


Most gui programmers using the standard tkinter framework has ecountered this error at least once when trying to change the ugly looking red tkinter default icon. I had my share recently and tried to trace the error for days without success and even nearly ported my program to another framework before I arrived at a solution.
Read More
// // 1 comment

Think python - Book review

Being a newbie in programming, the first book that caught my fancy was Think python - How to think like a computer scientist by Allen B. Downey. The book introduces you to programming in general starting from basic concepts including variables, operators, expressions and statements before delving into python programming in full.
Read More

Tuesday, 1 September 2015

// // Leave a Comment

My ecounter with wxpython

I was trying to program a graphical user interface today for one of my projects when I ran into a very frustrating bug when I had barely started. I had always been a fan of Tkinter (I just have a feel there’s a unique reason it was selected to be shipped along with python) but I decided to wet my hands with wxpython today. I had the following lines of codes


Read More

Sunday, 4 January 2015

// // 13 comments

Top 5 books to learn python programming for beginers

Programming can be made easy if given the right approach to learning. While some books actually makes programming as easy as giving your younger one a set of instructions to carry out, some makes it look like an underground mission impossible to attain. I have taken time out to list top 5 books that can make learning programming in python extremely easy for you.
Read More

Sunday, 28 December 2014

// // Leave a Comment

Python: Searching for a string in a string.

There are two nice python string methods to search for a sub string in a string. their usage depends on what you want to achieve.
Read More