• Twitter
  • Facebook
  • Google+
  • Instagram
  • Youtube

Employment

Education

Skills & Things about me

Python Basics

Python Basics

Author:- Tushar Sonu Lambole

-------------------------------------------------------------------------------
1. Activate the virtualEnvi 

Step A. Open terminal and go to the path of VirtualEnvi
$ cd /Users/tusharlambole/Documents/Development/Projects/DjangoProjects/PycharmProjects/VirtualEnviAR/bin

Step B. Activate the Virtual Envi
$  source activate

Step C. Go to the package folder which have to install
$ cd /Users/tusharlambole/Documents/Development/TusharHelpDesk/AR\ Python\ CMS\ Related/python-vuforia-master

Step D. install package in Virtual Envi

(VirtualEnviAR)Tushars-Mac-mini:python-vuforia-master tusharlambole$ sudo /Users/tusharlambole/Documents/Development/Projects/DjangoProjects/PycharmProjects/VirtualEnviAR/bin/python setup.py install

-------------------------------------------------------------------------------















Django Model creation Basics

Django Model creation Basics

Author:- Tushar Sonu Lambole

This post includes the basics of Model creation in Django

1. AutoIncrement and primary field
class ProjectMaster(models.Model):
    p_id = models.AutoField(primary_key=True)
   
2. Display text for model fields
class ProjectMaster(models.Model):
    p_name = models.CharField(verbose_name='Project Name', max_length=150)

3. Ordering the data in admin view 
class ProjectMaster(models.Model):
   class Meta:
        ordering = ('-p_date',)

4. Display model in admin site
class ProjectMasterAdmin(admin.ModelAdmin):
    list_display = ('p_id','p_name','p_description','p_date')

admin.site.register(ProjectMaster, ProjectMasterAdmin)

5. Foreign Key 
class ClientMaster(models.Model):
    c_id = models.AutoField(primary_key=True)
    p_fk = models.ForeignKey(ProjectMaster,verbose_name='Project')

6. ImageUploader with validation for ".png" extension and Dynamic ImagePath
class ClientMaster(models.Model):
   c_name = models.CharField(max_length=150,verbose_name='Name')

   def image_path(instance, filename):
        return os.path.join('ImagesFiles', str(instance.c_name), str(instance.c_name)+'.png')
 
   def validate_file_extension(value):
        if not value.name.endswith('.png'):
            raise ValidationError(u'Error: Only .Png files')

   c_logo = models.ImageField(upload_to=image_path, validators=[validate_file_extension],verbose_name='Logo Image')

7. View uploaded images 

A) in settings.py

MEDIA_ROOT = '/Users/tusharlambole/Documents/Development/Projects/DjangoProjects/PycharmProjects/TusharWebApp/'

MEDIA_URL = 'http://127.0.0.1:8000/'

B) in Url.py

urlpatterns = patterns('',
url(r'^(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': settings.MEDIA_ROOT}),
)





Django - Rest - API

Django - Rest - API

Author- Tushar Sonu Lambole

Installed packages
1) Django
2) PIL  (for image related)
3) Django Rest framework (for Rest APIs)
4) pip
5) South (for database alterations)


1. To view the table in sqlite database python

python manage.py shelldb
SELECT * FROM sqlite_master WHERE type='table';
DROP TABLE appname_modelname
.exit
2. Drops and re-creates the tables used by the models of this app.
python manage.py reset app_name
----------------------------------------------------------------------------------------------------
AR App

models.py

__author__ = 'tusharlambole'

from django.db import models
from django.contrib import admin
import os

class ProjectMaster(models.Model):
    p_id = models.AutoField(primary_key=True)
    p_name = models.CharField(max_length=150)
    p_description = models.TextField()
    p_date = models.DateTimeField()

    def __unicode__(self):
        return (self.p_name)

    class Meta:
        ordering = ('-p_date',)


class ProjectMasterAdmin(admin.ModelAdmin):
    list_display = ('p_id','p_name','p_description','p_date')

admin.site.register(ProjectMaster, ProjectMasterAdmin)

class ClientMaster(models.Model):

    c_id = models.AutoField(primary_key=True)
    p_fk = models.ForeignKey(ProjectMaster)
    c_name = models.CharField(max_length=150)

    def image_path(instance, filename):
        return os.path.join('ImagesFiles', str(instance.c_name), str(instance.c_name)+'.png')

    c_access_key = models.CharField(max_length=150)
    c_secret_key = models.CharField(max_length=150)
    c_is_active = models.BooleanField(default=False)
    c_logo = models.ImageField(upload_to=image_path)

    def __unicode__(self):
        return (self.c_name)

    class Meta:
        ordering = ('c_id',)

class ClientMasterAdmin(admin.ModelAdmin):
    list_display = ('c_id','c_name','c_is_active','c_logo')

admin.site.register(ClientMaster,ClientMasterAdmin)
----------------------------------------------------------------------------------------------------
serializers.py

from models import ProjectMaster,ClientMaster
from rest_framework import serializers

class ProjectMasterSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = ProjectMaster
fields = ('p_name','p_description','p_date')

class ClientMasterSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = ClientMaster
        fields = ('c_id','c_name','c_is_active','p_fk','c_access_key','c_secret_key','c_logo')
----------------------------------------------------------------------------------------------------

views.py

__author__ = 'tusharlambole'

from models import ProjectMaster,ClientMaster
from serializers import ProjectMasterSerializer,ClientMasterSerializer
from rest_framework import viewsets

class ProjectMasterViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
queryset = ProjectMaster.objects.all()
serializer_class = ProjectMasterSerializer

class ClientMasterViewSet(viewsets.ModelViewSet):
    queryset = ClientMaster.objects.all()
    serializer_class = ClientMasterSerializer
----------------------------------------------------------------------------------------------------

settings.py

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'FirstSite',
    'rest_framework',
    'AR',
    'south',
)

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
    'PAGINATE_BY': 10
}

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
----------------------------------------------------------------------------------------------------
urls.py

from django.conf.urls import patterns, include, url
from FirstSite.views import archieve,GroupViewSet,UserViewSet
from rest_framework import routers
from AR.views import ProjectMasterViewSet,ClientMasterViewSet

from django.contrib import admin
admin.autodiscover()

router = routers.DefaultRouter()
router.register(r'users', UserViewSet)
router.register(r'groups', GroupViewSet)
router.register(r'projectmaster', ProjectMasterViewSet)
router.register(r'clientmaster', ClientMasterViewSet)

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'TusharWebApp.views.home', name='home'),
    url(r'^blog/', include('FirstSite.urls')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))

)
----------------------------------------------------------------------------------------------------
FirstSite App

templates/base.html

<html>
<style type="text/css">
body { color: #efd; background: #453; padding: 0 5em; margin: 0 } h1 { padding: 2em 1em; background: #675 }
h2 { color: #bf8; border-top: 1px dotted #fff; margin-top: 2em } p { margin: 1em 0 }
</style>
<body>
<h1>Tushar Sonu Lambole</h1>
{% block content %}
{% endblock %}
</body>
</html>
----------------------------------------------------------------------------------------------------
templates/archieve.html

{% extends "base.html" %}
{% block content %}
{% for post in posts %}
    <h2>{{ post.title }}
    </h2> <p>{{ post.timestamp|date:"l, F jS" }}</p>
    <p>{{ post.body }}</p>
{% endfor %}
{% endblock %}
----------------------------------------------------------------------------------------------------
models.py

from django.db import models
from django.contrib import admin

# Create your models here.

class BlogPost(models.Model):
    title = models.CharField(max_length=150)
    body = models.TextField()
    timestamp = models.DateTimeField()

    class Meta:
        ordering = ('-timestamp',)

class BlogPostAdmin(admin.ModelAdmin):
    list_display = ('title','timestamp')

admin.site.register(BlogPost, BlogPostAdmin)
----------------------------------------------------------------------------------------------------
urls.py

from django.conf.urls import  patterns, include, url
from FirstSite.views import archieve


urlpatterns = patterns('',url(r'^$',archieve),)
----------------------------------------------------------------------------------------------------
views.py

from django.shortcuts import render
from django.template import loader, Context
from django.http import HttpResponse
from FirstSite.models import BlogPost

def archieve(request):
    posts = BlogPost.objects.all()
    t = loader.get_template("archive.html")
    c = Context({ 'posts': posts })
    return HttpResponse(t.render(c))





Photoshop Basics

Photoshop Basics

Author:- Tushar Sonu Lambole

I am new to Photoshop. My first exercise in Photoshop. will update when will learn new things.

Q1. How to create transparent background image with height and width of 512 pixels using Photoshop?
1. Make Image transparent
=> A. Click and Hold on eraser tool
B. Select "Magic eraser" option
C. Click on the image area to make it transparent.

2. Move Image
=> A. ctrl + T

3. Resize image 
=> A. Select File option
B. Select "Save for Web..."
C. Select "PNG-24" from dropdown
D. Check "Transparency" checkBox
E. In Image Size panel W="512", H="512"
F. click "Save"



Page 1 of 3123Next