How to automatically update the date field through Django Class model

How to automatically update the date field through Django Class model::

 

For the update of table field automatically from the django model we need to use

the auto_now=False and auto_now_add=False field options

date_created = models.DateTimeField(auto_now_add=True)
date_updated = models.DateTimeField(auto_now=True)

From Django ::

DateField

class DateField([auto_now=Falseauto_now_add=False**options])

A date, represented in Python by a datetime.date instance. Has a few extra, optional arguments:

DateF
ield.auto_now
Automatically set the field to now every time the object is saved. Useful for “last-modified” timestamps. Note that the current date is always used; it’s not just a default value that you can override.
DateField.auto_now_add
Automatically set the field to now when the object is first created. Useful for creation of timestamps. Note that the current date is always used; it’s not just a default value that you can override.

The default form widget for this field is a TextInput. The admin adds a JavaScript calendar, and a shortcut for “Today”. Includes an additional invalid_date error message key.

Example::

from django.db import models

class Task(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

sources:
https://docs.djangoproject.com/en/1.7/ref/models/fields/#datefield

https://timonweb.com/tutorials/automatic-created-and-updated-datetime-fields-for-django-models/

 

What is Elastic search Output if running in python or django

For OUTPUT: type: http://localhost:9200/
Result:
{

  "status" : 200,

  "name" : "Skin",

  "cluster_name" : "elasticsearch",

  "version" : {

    "number" : "1.7.2",

    "build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",

    "build_timestamp" : "2015-09-14T09:49:53Z",

    "build_snapshot" : false,

    "lucene_version" : "4.10.4"

  },  
  "tagline" : "You Know, for Search"
}

 

How to Create Python Virtual Environment in Windows and Linux

Creating Python Virtual Environment in Windows and Linux

A Virtual Environment is a python environment, that is an isolated working copy of Python which allows you to work on a specific project without affecting other projects. So, basically it is a tool that enables multiple side-by-side installations of Python, one for each project.

-:: Creating virtual environment in Linux ::-


# If pip is not in your system::

$ sudo apt-get install python-pip

# Then install virtualenv::

$ pip install virtualenv

# Now check your installation::

$ virtualenv --version

# Create a virtual environment now,

$ virtualenv virtualenv_name

After this command, a folder named virtualenv_name will be created.

You can name anything to it. If you want to create a virtualenv for specific python version, type

$ virtualenv -p /usr/bin/python3 virtualenv_name

or

$ virtualenv -p /usr/bin/python2.7 virtualenv_name

# Now at last we just need to activate it, using command

$ source virtualenv_name/bin/activate

# Now you are in a Python virtual environment. You can deactivate using

$ deactivate

 

-:: Creating Python virtualenv in Windows ::-


If python is installed in your system, then pip comes in handy.
So simple steps are:
1) Install virtualenv using

 > pip install virtualenv

2) Now in which ever directory you are, this line below will create a virtualenv there

> virtualenv myenv

And here also you can name it anything.

3) Now if you are same directory then type,

 > myenv\Scripts\activate

You can explicitly specify your path too. Similarly like Linux you can deactivate it like

$ deactivate