Posts

Windows GDAL Installation in Python Django Project

 First Download the gdal wheel from  here https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal now pip install the gdal in env jus like normally also install psycopg2 and pscopg2-binary add postgres database to the settings if the liberror then add the version in django contrib gis gdal libgdal.py add to lib_name get the verison of dll from sitescrips osgeo,  add the path into ypur settings import   os if   os . name  ==  'nt' :      VENV_BASE  =  os . environ [ 'VIRTUAL_ENV' ]      os . environ [ 'PATH' ] =  os . path . join ( VENV_BASE ,  'Lib \\ site-packages \\ osgeo' ) +  ';'  +  os . environ [ 'PATH' ]      os . environ [ 'PROJ_LIB' ] =  os . path . join ( VENV_BASE ,  'Lib \\ site-packages \\ osgeo \\ data \\ proj' ) +  ';'  +  os . environ [ 'PATH' ]

Main Template

  {% load static  %} <! DOCTYPE   html > < html > < head >      < title > CRM </ title >      < link   rel = "stylesheet"   href = "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"   integrity = "sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"   crossorigin = "anonymous" >           < link   rel = "stylesheet"   type = "text/css"   href = "{% static '/css/main.css' %}" > </ head > < body >     {% include 'accounts/navbar.html' %}      < div   class = "container-fluid" >     {% block content  %}     {%  endblock %} < hr > < h5 > Our footer </ h5 > </ body > < script   src = "https://code.jquery.com/jquery-3.3.1.slim.min.js"   integrity = "sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"   crossorigin = "anonym

Important Django Query Demos

#***(1)Returns all customers from customer table customers = Customer.objects.all() #(2)Returns first customer in table firstCustomer = Customer.objects.first() #(3)Returns last customer in table lastCustomer = Customer.objects.last() #(4)Returns single customer by name customerByName = Customer.objects.get( name = 'Peter Piper' ) #***(5)Returns single customer by name customerById = Customer.objects.get( id = 4 ) #***(6)Returns all orders related to customer (firstCustomer variable set above) firstCustomer.order_set.all() #(7)***Returns orders customer name: (Query parent model values) order = Order.objects.first()  parentName = order.customer.name #(8)***Returns products from products table with value of "Out Door" in category attribute products = Product.objects.filter( category = "Out Door" ) #(9)***Order/Sort Objects by id leastToGreatest = Product.objects.all().order_by( 'id' )  greatestToLeast = Product.objects.all().order_by( '-id' ) 

The Dashboard Accounts Django Source

VIEWS from  django.shortcuts  import  render, redirect  from  django.http  import  HttpResponse from  django.forms  import  inlineformset_factory from  django.contrib.auth.forms  import  UserCreationForm from  django.contrib.auth  import  authenticate, login, logout from  django.contrib  import  messages from  django.contrib.auth.decorators  import  login_required # Create your views here. from  .models  import  * from  .forms  import  OrderForm, CreateUserForm from  .filters  import  OrderFilter def   registerPage ( request ):      if  request.user.is_authenticated:          return  redirect( 'home' )      else :         form = CreateUserForm()          if  request.method ==  'POST' :             form = CreateUserForm(request.POST)              if  form.is_valid():                 form.save()                 user = form.cleaned_data.get( 'username' )                 messages.success(request,  'Account was created for '  + user)                  return