Posts

Showing posts from July, 2014

5 most common Rsync command usage examples

Image
rsync is a command for remote sync. It is used to synchronise one location to another in a simple way. Location is meant to be local directory, server or remote web server or whatever accessible by ssh. Advantages of using rsync over other tools is speed and bandwidth requirements. First time rsync copies entire contents of the directory provided and increments changes over next sync times. Command syntax: $ rsync options source destination 1. Synchronising local directories: $ rsync -zvr /tmp/logs/ /tmp/logs1/ building file list ... done created directory /tmp/ logs1 ./ log. log sent 98 bytes received 48 bytes 292.00 bytes/sec total size is 0 speedup is 0.00 $ Used rsync command options here: -z is for compression -v is for verbose output -r is for recursive directory scanning By default rsync does not preserve timestamps.  2. Preserve timestamps and permissions during sync: $ rsync -azvr /tmp/logs/ /tmp/logs

Django adding custom widget to Django Admin

Image
Sometimes you need to get out of standard behaviour of your Django admin. It means expanding its functionality with custom things. In our case we have a model that we want to add a custom html element. Button that must load something via AJAX from another place to be exact. We have a typical Django polls application for simplicity. Here is its structure: First of all we need to create a structure. So here comes our model: # models.py from django.db import models class Poll (models.Model): question = models.CharField(max_length= 200 ) pub_date = models.DateTimeField( 'date published' ) We have to have our django application admin configuration to display that model: # admin.py from django.contrib import admin from polls.models import Poll admin.site.register(Poll) It will look in Django admin like so: You can see polls available here in admin. You can do all the typical things with Polls model. Add/Delete/Edit... Using standard D

Virtualenv for Django

Image
One of main features and troubles for Django projects is the Django version you are using. Example for this would be the occasion of starting project for Django 1.4.x version. Trying to run it under Django 1.7.x would lead to various troubles, counting template changes, misconfiguration errors and so on. Solution is to use virtual environment. The tool for this is called Virtualenv . It is a wrapper for a python interpreter. It enables you to have multiple versions of python packages that run independently. The Virtualenv creates you a standalone environment. Basically it copies and keeps a system Python of yours in a specified directory. All the python packages will be installed there. (In case you have not forgot to activate it first, of course) Lets get started then. We need Virtualenv itself for the first. There are many ways to install it depending on your system . Most obvious to use pip. Your installation command will look something like that: pip install virtualenv Thi