'''from django.
db import models
from [Link] import User
#list to be used
Province =[
('Bulawayo', 'Bulawayo'),
('Harare', 'Harare'),
('Manicaland','Manicaland'),
('Mashonaland Central','Mashonaland Central'),
('Mashonaland East', 'Mashonaland East'),
('Mashonaland West', 'Mashonaland West'),
('Masvingo', 'Masvingo'),
('Matabeleland North', 'Matabeleland North'),
('Matabeleland South', 'Matabeleland South'),
('Midlands', 'Midlands')
]
# Create your models here.
def get_current_user():
return [Link]() #way to get the current user
# model that push data into the database
class GRS_INSTITUTE_STORAGE([Link]):
name = [Link](max_length=100, primary_key=True)
document = [Link](upload_to='docs')
shapefile = [Link](upload_to='csv')
raster = [Link](upload_to='pics')
data = [Link](upload_to='data')
description = [Link]()
province = [Link](max_length=100, choices=Province)
latitude = [Link](default=0.0, editable=False) # Modified field type
longitude = [Link](default=0.0, editable=False)
country = [Link](default='Zimbabwe', max_length=100, editable=False)
Uploaded_At = [Link](auto_now=True)
Uploaded_By = [Link](User, on_delete=[Link], default=get_current_user,
editable=False)
def __str__(self):
return [Link]
def snipet(self):
return [Link][: 100] + '...'
#function that aut-fill coordinates fields
def save(self, *args, **kwargs):
if [Link] == 'Bulawayo':
[Link] = -20.105394800383586; [Link] = 28.542685599999995
elif [Link] == 'Harare':
[Link] = -17.856703500474605; [Link] = 31.060158400000002
elif [Link] == 'Manicaland':
[Link] = -19.018842200446677; [Link] = 32.368888999999996
elif [Link] == 'Mashonaland Central':
[Link] = -16.742872000463453; [Link] = 31.295208600000002
elif [Link] == 'Mashonaland East':
[Link] = -17.792732300474952; [Link] = 31.7678044
elif [Link] == 'Mashonaland West':
[Link] = -17.144900100471617; [Link] = 29.828988500000005
elif [Link] == 'Masvingo':
[Link] = -20.74539570033053; [Link] = 31.334138
elif [Link] == 'Matabeleland North':
[Link] = -18.928371500450336; [Link] = 27.499223099999995
elif [Link] == 'Matabeleland South':
[Link] = -20.736480100331352; [Link] = 28.939649499999994
elif [Link] == 'Midlands':
[Link] = -19.278504300434808; [Link] = 29.879085199999995
super().save(*args, **kwargs)'''
from [Link] import models
from [Link] import User
#list to be used
Province =[
('Bulawayo', 'Bulawayo'),
('Harare', 'Harare'),
('Manicaland','Manicaland'),
('Mashonaland Central','Mashonaland Central'),
('Mashonaland East', 'Mashonaland East'),
('Mashonaland West', 'Mashonaland West'),
('Masvingo', 'Masvingo'),
('Matabeleland North', 'Matabeleland North'),
('Matabeleland South', 'Matabeleland South'),
('Midlands', 'Midlands')
]
# Create your models here.
def get_current_user():
return [Link]() #way to get the current user
class GRS_INSTITUTE_STORAGE([Link]):
name = [Link](max_length=100, primary_key=True)
document = [Link](upload_to='docs')
shapefile = [Link](upload_to='csv')
raster = [Link](upload_to='pics')
data = [Link](upload_to='data')
description = [Link]()
Uploaded_At = [Link](auto_now=True)
Uploaded_By = [Link](User, on_delete=[Link], default=get_current_user,
editable=False)
province = [Link](max_length=100, choices=Province)
def __str__(self):
return [Link]
def snipet(self):
return [Link][:100] + '...'
class LocationModel([Link]):
province = [Link](max_length=100, choices=Province)
latitude = [Link](default=0.0, editable=False)
longitude = [Link](default=0.0, editable=False)
country = [Link](default='Zimbabwe', max_length=100, editable=False)
projects = [Link](default=1, editable=False)
def __str__(self):
return [Link]
# Function that aut-fills coordinate fields
def save(self, *args, **kwargs):
# Check if the province already exists
existing_location = [Link](province=[Link]).first()
if existing_location:
# Remove the existing row and replace it
existing_location.delete()
existing_location.projects += 1
existing_location.save()
else:
# Set the coordinates based on the province
if [Link] == 'Bulawayo':
[Link] = -20.105394800383586
[Link] = 28.542685599999995
elif [Link] == 'Harare':
[Link] = -17.856703500474605
[Link] = 31.060158400000002
elif [Link] == 'Manicaland':
[Link] = -19.018842200446677
[Link] = 32.368888999999996
elif [Link] == 'Mashonaland Central':
[Link] = -16.742872000463453
[Link] = 31.295208600000002
elif [Link] == 'Mashonaland East':
[Link] = -17.792732300474952
[Link] = 31.7678044
elif [Link] == 'Mashonaland West':
[Link] = -17.144900100471617
[Link] = 29.828988500000005
elif [Link] == 'Masvingo':
[Link] = -20.74539570033053
[Link] = 31.334138
elif [Link] == 'Matabeleland North':
[Link] = -18.928371500450336
[Link] = 27.499223099999995
elif [Link] == 'Matabeleland South':
[Link] = -20.736480100331352
[Link] = 28.939649499999994
elif [Link] == 'Midlands':
[Link] = -19.278504300434808
[Link] = 29.879085199999995
super().save(*args, **kwargs)
''' def save(self, *args, **kwargs):
if grs_instance:
if grs_instance.province == 'Bulawayo':
[Link] = 'Bulawayo'
[Link] = -20.105394800383586
[Link] = 28.542685599999995
elif grs_instance.province == 'Harare':
[Link] = 'Harare'
[Link] = -17.856703500474605
[Link] = 31.060158400000002
elif grs_instance.province == 'Manicaland':
[Link] = 'Manicaland'
[Link] = -19.018842200446677
[Link] = 32.368888999999996
elif grs_instance.province == 'Mashonaland Central':
[Link] = 'Mashonaland Central'
[Link] = -16.742872000463453
[Link] = 31.295208600000002
elif grs_instance.province == 'Mashonaland East':
[Link] = 'Mashonaland East'
[Link] = -17.792732300474952
[Link] = 31.7678044
elif grs_instance.province == 'Mashonaland West':
[Link] = 'Mashonaland West'
[Link] = -17.144900100471617
[Link] = 29.828988500000005
elif grs_instance.province == 'Masvingo':
[Link] = 'Masvingo'
[Link] = -20.74539570033053
[Link] = 31.334138
elif grs_instance.province == 'Matabeleland North':
[Link] = 'Matabeleland North'
[Link] = -18.928371500450336
[Link] = 27.499223099999995
elif grs_instance.province == 'Matabeleland South':
[Link] = 'Matabeleland South'
[Link] = -20.736480100331352
[Link] = 28.939649499999994
elif grs_instance.province == 'Midlands':
[Link] = 'Midlands'
[Link] = -19.278504300434808
[Link] = 29.879085199999995
super().save(*args, **kwargs)'''
'''class LocationModel([Link]):
province = [Link](primary_key=True, max_length=100, choices=Province)
latitude = [Link](default=0.0, editable=False)
longitude = [Link](default=0.0, editable=False)
country = [Link](default='Zimbabwe', max_length=100, editable=False)
projects = [Link](default=1, editable=False)
def __str__(self):
return [Link]
#function that aut-fill coordinates fields
def save(self, *args, **kwargs):
if [Link] == 'Bulawayo':
[Link] = -20.105394800383586; [Link] = 28.542685599999995
elif [Link] == 'Harare':
[Link] = -17.856703500474605; [Link] = 31.060158400000002
elif [Link] == 'Manicaland':
[Link] = -19.018842200446677; [Link] = 32.368888999999996
elif [Link] == 'Mashonaland Central':
[Link] = -16.742872000463453; [Link] = 31.295208600000002
elif [Link] == 'Mashonaland East':
[Link] = -17.792732300474952; [Link] = 31.7678044
elif [Link] == 'Mashonaland West':
[Link] = -17.144900100471617; [Link] = 29.828988500000005
elif [Link] == 'Masvingo':
[Link] = -20.74539570033053; [Link] = 31.334138
elif [Link] == 'Matabeleland North':
[Link] = -18.928371500450336; [Link] = 27.499223099999995
elif [Link] == 'Matabeleland South':
[Link] = -20.736480100331352; [Link] = 28.939649499999994
elif [Link] == 'Midlands':
[Link] = -19.278504300434808; [Link] = 29.879085199999995
super().save(*args, **kwargs)'''