Skip to content

nikita-harripersadh/django-gis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django-gis Project

Overview

This is a Django-based web application for managing farm data. It allows users to perform CRUD operations on farming models, such as Crops and Animals, and integrates GIS functionality using GDAL and SpatiaLite. The project was completed in three assignments:

  • Assignment 1: Django models, migrations, and admin customisation

  • Assignment 2: Wildlife app + Django ORM queries

  • Assignment 3: Views, templates, and CRUD functionality

  • Assignment 4: Function-Based Views (FBVs), BaseModel for shared fields, pagination, success messages, and improved UI

  • Assignment 5: ORM Testing using Django’s built-in testing framework

Features

  • CRUD operations for Farm Locations, Crops, and Irrigation Zones
  • BaseModel with last_update (auto-update timestamp) and last_update_by (tracks user who last modified a record)
  • Pagination on list views (10 items per page) -Success messages on create/update/delete actions
  • User-friendly navigation and intuitive interface
  • Django Admin integration with read-only tracking fields
  • GIS support using GDAL
  • Fully automated Django tests for ORM queries (Assignment 5)

Setup Instructions

1. Clone the Repository

git clone https://github.com/nikita-harripersadh/django-gis.git
cd django-gis

2. Create and Activate Virtual Environment

python -m venv venv
venv\Scripts\activate           # Windows

3. Install Dependencies

pip install -r requirements.txt

4. Apply Migrations

python manage.py makemigrations
python manage.py migrate

5. Create a Superuser

python manage.py createsuperuser

6. Run the Development Server

python manage.py runserver

Running ORM Assignment Tasks (Assignment 2)

Use the custom Django command:

python manage.py run_orm
All 12 ORM tasks are implemented in:

wildlife/management/commands/run_orm.py

CRUD Views (Assignment 3)

Two models from the farming app have full CRUD operations using Class-Based Views:

Views Used

ListView

DetailView

CreateView

UpdateView

DeleteView

Template Structure

templates/
    farming/
        model_list.html
        model_detail.html
        model_form.html
        model_confirm_delete.html

URL Example

path("farms/", FarmListView.as_view(), name="farm-list"),
path("farms/<int:pk>/", FarmDetailView.as_view(), name="farm-detail"),

Assignment 4 – Function-Based Views (FBVs)

Features:

Paginated list views

Auto-update last_update and last_update_by

Success messages

Clean UI templates

Example URL patterns (FBVs):

path("farms/", farm_list, name="farm_list"),
path("farms/add/", farm_create, name="farm_create"),
path("farms/<int:pk>/", farm_detail, name="farm_detail"),
path("farms/<int:pk>/edit/", farm_update, name="farm_update"),
path("farms/<int:pk>/delete/", farm_delete, name="farm_delete"),

Templates

farm/templates/farm/
    farmlocation_list.html
    farmlocation_detail.html
    farmlocation_form.html
    farmlocation_confirm_delete.html
    crop_list.html
    crop_detail.html
    crop_form.html
    crop_confirm_delete.html
    zone_list.html
    zone_detail.html
    zone_form.html
    zone_confirm_delete.html

Django Admin

Custom admin classes:
list_display
list_filter
search_fields
readonly_fields for last_update and last_update_by

Assignment 5 – Django Testing (ORM Tests)

A full automated test suite was implemented to validate ORM queries from Assignment 2.

All tests are located in:

wildlife/tests.py

Run tests:

python manage.py test wildlife

Branching Structure

The project follows the lesson-based branching:

django-lesson-1-admin

django-lesson-2-orm

django-lesson-3-cbv

django-lesson-4-fbv

django-lesson-5-test

📘 Setting Up GDAL on Windows (Using VS Code + Conda)

GDAL does not install cleanly on Windows with the latest Python versions (e.g., Python 3.12+). To avoid installation errors, this project uses a dedicated Conda environment with a compatible Python version.

Follow the steps below to set up GDAL and run this Django GIS project successfully.

1. Install required tools:

Download Miniconda (Restart after install)

2. Create a Conda Environment With a Supported Python Version

GDAL works best with Python 3.10 or 3.11 on Windows.

Open Anaconda Prompt or VS Code terminal

conda create -n gdal-env python=3.10

3. Activate the Environment in VS Code

conda activate gdal-env

You should see:

(gdal-env) C:\Users\yourname>

4. Install GDAL Using Conda-Forge (Most Important Step)

conda install -c conda-forge gdal

5. Install Django and Project Dependencies

Inside the gdal-env environment:

pip install django

6. Test GDAL Installation

Inside VS Code terminal:

python -c "import osgeo; print(osgeo.__version__)"

You should see a version number like:

3.6.2

7. Run the Django Project (inside VS Code)

Navigate to your project folder:

cd path/to/your/project

Run migrations:

python manage.py migrate

Start the Django development server:

python manage.py runserver

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages