LOAD DATA LOCAL INFILE 'file-path/file_name.csv' INTO TABLE table_name
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'

For more details
  http://dev.mysql.com/doc/refman/5.1/en/load-data.html



 

How to do add pagination in django framework

Posted In: . By Webdevelopmentlogics


In views.py add the below code
  d = FlatPage.objects.all() // Flatpage is the Model class
    paginator = Paginator(d, 2) # Show 2 help on each row
    page = request.GET.get('page')
   
    try:
        helps = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        helps = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        helps = paginator.page(paginator.num_pages)
    return render_to_response("flatpages_plus/list.html",{
            "data": helps }, RequestContext(request),
        )

In the template add teh following code

 div class="pagination"
         

                {% if data.has_previous %}
                 
  • previous

  •             {% endif %}
                {% if data.page_range_data.show_first %}
                 
  • 1

  •             {% endif %}
                {% for i in data.page_range_data.page_range %}
                    {% ifequal i data.number %}
                        {{ i }}
                    {% else %}
                       
  • {{ i }}

  •                 {% endifequal %}
                {% endfor %}
                {% if data.page_range_data.show_last %}
                   
  • {{ data.paginator.num_pages }}

  •             {% endif %}
                {% if data.has_next %}
                   
  • next

  •             {% endif %}
               

        /div

 

helpful links to learn django forms

Posted In: . By CreativeSolutions
 


1. Install virtualenv by dowloading or using the command 'yum install virtualenv' in terminal
 2. Then in the project's folder, run the command
     virtualenv [name] ex: venv
    with this you can add -no-site-packages or other options
 3. Then install django and necessary module in it.
 4. from the 'venv' directory created on executing the command 'virtualenv'
    run the command 'source bin/activate' in terminal
 5. run the command 'deactivate' from terminal to exit

 

How to set and print views variables in template

Posted In: . By CreativeSolutions


In the view
    return render(request, 'admin/user/form.html', {'form': form,'error_msg': error_msg})
In the template
    form action="" method="post">{{ form.as_p }}
    input type="submit" value="Save" /
    /form
    {% if error_msg %}
        {{ error_msg }}
    {% endif %}