How to show all the form errors in django form

Posted In: . By Webdevelopmentlogics


{% if my_form.errors %}

div id="errors"
div class="inner"
There were some  errors in the data you entered. Please correct the following
{{ my_form.non_field_errors }}
ul
{% for field in my_form %}
{% if field.errors %}li{{ field.label }}: {{ field.errors|striptags }}/li{% endif %}
{% endfor %}
/ul
/div
/div

{% endif %}

 

Django query with list of values in where clause

Posted In: , . By CreativeSolutions


If we need to fetch data like the MySQL IN clause, we can do it by using filter function with the list of values
user_ids= [1,2,3]
Ex. User.objects.filter(id__in = user_ids)

 


import time

Then add the below code
#Finding the daylight saving time
    is_dst = time.daylight and time.localtime().tm_isdst > 0
    utc_offset = (time.altzone if is_dst else time.timezone)
#Checking for negative and positve offset values
    if(utc_offset > 0):
        utc_offset_hours = (utc_offset / 3600)
        sign = '- '
    else:
        utc_offset_hours = (-(utc_offset) / 3600)
        sign = '+ '
    utc_offset_minutes =  (utc_offset % 3600) / 60
#Converting Integer values to string before concatenating
    utc_offset = sign + str(utc_offset_hours) + '.' +str(utc_offset_minutes)
    print utc_offset

 

Install new python package in virtualenv

Posted In: , . By Webdevelopmentlogics


  1. Enable virtualevn using command 'soure bin/activate'
  2. Then try the command 'echo $PATH' to show it's path. Then it will show the path with like given below
     /var/path/virtauanenv/bin
  3. Go the the package folder which you want to install. Then use the below command
     /home/user/package/folder$ /var/path/virtauanenv/bin/python setup.py install

 


First we need to read the image and encode it using base64(ex: $data = chunk_split(base64_encode($pictureData)) ) . Then we can directly use it in the html img src attribute
img src="data:image/gif;base64{{$data}}"

 


 1. Add the following in the settings file
    INSTALLED_APPS = (
    .......
    'rest_framework.authtoken',
    )
 2. In the PUBLIC_URLS add the url configuration to support the api calls
     re.compile(r'^/folder/'),
 3. Change the url configration file to support the api urls
    url(r'^client/', include('apps.admin.client.urls')),
    url(r'^server/', include('apps.api.server.urls')),

 


To convert it uses the function eval
Ex:
  >>> lUnicodeData = u'[0,1,2]'
  >>> eval(lUnicodeData)
       [0, 1, 2]

 

Install mysql-workbench in Ubuntu

By CreativeSolutions


1. Open a terminal window.

2. Type in the following commands then hit Enter after each.

sudo add-apt-repository ppa:olivier-berten/misc
sudo apt-get update
sudo apt-get install mysql-workbench

3. To start the application, use this command.

    mysql-workbench &