i can't add geo location in postgis data base

hey i am using gdal to save cordinates but i found an error plese help me if you want any other file reply me or ask anything about code

here is me error

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/admin/job/job/add/

Django Version: 4.0.4
Python Version: 3.10.4
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.gis',
 'job.apps.JobConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\admin\options.py", line 683, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\utils\decorators.py", line 133, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\views\decorators\cache.py", line 62, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\admin\sites.py", line 242, in inner
    return view(request, *args, **kwargs)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\admin\options.py", line 1885, in add_view
    return self.changeform_view(request, None, form_url, extra_context)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\utils\decorators.py", line 46, in _wrapper
    return bound_method(*args, **kwargs)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\utils\decorators.py", line 133, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\admin\options.py", line 1745, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\admin\options.py", line 1791, in _changeform_view
    form_validated = form.is_valid()
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\forms\forms.py", line 205, in is_valid
    return self.is_bound and not self.errors
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\forms\forms.py", line 200, in errors
    self.full_clean()
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\forms\forms.py", line 433, in full_clean
    self._clean_fields()
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\forms\forms.py", line 445, in _clean_fields
    value = field.clean(value)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\gis\forms\fields.py", line 90, in clean
    geom.transform(self.srid)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\gis\geos\geometry.py", line 480, in transform
    g = gdal.OGRGeometry(self._ogr_ptr(), srid)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\gis\gdal\geometries.py", line 123, in __init__
    self.srs = srs
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\gis\gdal\geometries.py", line 289, in _set_srs
    sr = SpatialReference(srs)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\gis\gdal\srs.py", line 114, in __init__
    self.import_epsg(srs_input)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\gis\gdal\srs.py", line 300, in import_epsg
    capi.from_epsg(self.ptr, epsg)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\gis\gdal\prototypes\errcheck.py", line 120, in check_errcode
    check_err(result, cpl=cpl)
  File "D:\Django\Jobbee\myenv\lib\site-packages\django\contrib\gis\gdal\error.py", line 59, in check_err
    raise e(msg)

Exception Type: GDALException at /admin/job/job/add/
Exception Value: OGR failure.

this is my models .py

from django.db import models
from datetime import *
from django.contrib.auth.models import User

from django.contrib.gis.db import models as gismodels
from django.contrib.gis.geos import Point

from django.core.validators import MinValueValidator, MaxValueValidator

# Create your models here.
class JobType(models.TextChoices):
    Permanent = 'Permanent'
    Temporary = 'Temporary'
    Inernship = 'Internship'
class Education(models.TextChoices):
    Bachelors = 'Bachelors'
    Masters = 'Masters'
    Phd = 'Phd'
class Industry(models.TextChoices):
    Business = 'Business'
    IT = 'IT'
    Banking = 'Banking'
    Education = 'Education'
    Telecommunication = 'Telecommunication'
    Others = 'Others'
class Experience(models.TextChoices):
    NO_EXPERIENCE = 'No Experience'
    ONE_YEAR= '1 Years'
    TWO_YEAR = '2 Years'
    THREE_YEAR_PLUS = '3 Years above'

def return_date_time():
    now = datetime.now()
    return now + timedelta(days=10)


class Job(models.Model):
    title = models.CharField(max_length=200,null=True)
    description = models.TextField(null=True)
    email = models.EmailField(max_length=100,null=True)
    address = models.CharField(max_length=100,null=True)
    JobType = models.CharField(
        max_length=10,
        choices=JobType.choices,
        default=JobType.Permanent
    )
    education = models.CharField(
        max_length=10,
        choices=Education.choices,
        default=Education.Bachelors
    )
    industry = models.CharField(
        max_length=30,
        choices=Industry.choices,
        default=Industry.Business
    )
    experience = models.CharField(
        max_length=20,
        choices=Experience.choices,
        default=Experience.NO_EXPERIENCE
    )
    # salary = models.IntegerField(default=1, validators=[MinValueValidator=(1) , MinValueValidator=(100000)] )
    salary = models.IntegerField(default=1)
    posititons = models.CharField(max_length=100,null=True)
    company = models.CharField(max_length=100,null=True)
    point = gismodels.PointField(default=Point(0.0,0.0))
    lastDate = models.DateTimeField(default=return_date_time)
    user = models.ForeignKey(User, on_delete=models.SET_NULL,null=True)
    createdAt = models.DateTimeField(auto_now_add=True)

this is my settings .py gdal lib

# Gdal 
VIRTUAL_ENV_BASE = os.environ.get('VIRTUAL_ENV')
print(VIRTUAL_ENV_BASE)

GEOS_LIBRARY_PATH = VIRTUAL_ENV_BASE + '/Lib/site-packages/osgeo/geos_c.dll'
GDAL_LIBRARY_PATH = VIRTUAL_ENV_BASE + '/Lib/site-packages/osgeo/gdal304.dll'

1 Like

It would probably be helpful to see the view and a sample of the data being posted.
(Actually, it appears that you’re trying to add this through the admin. If so, then just a sample of what you’re trying to enter in that field would be helpful.)