I have a GeoDjango model like below (in "data" app):
from django.contrib.gis.db import models
class FirstModel(models.Model):
data_id = models.IntegerField(blank=True, null=True)
model_base_date = models.DateTimeField(blank=True, null=True)
mpoly = models.MultiPolygonField(blank=True, null=True)
class Meta:
db_table = "first_model"
Here is how I used this model in LayerMapping class to import a test shapefile into my PostGIS database:
from django.contrib.gis.utils import LayerMapping
from data.models import FirstModel
from datetime import datetime
mapping = {
'mpoly' : 'MULTIPOLYGON',
}
world_shp = 'po/my_shapefile.shp'
lm = LayerMapping(FirstModel, world_shp, mapping, transform=False, )
lm.save(strict=True, )
After running the code above, I look inside the table in the database, and all of the model_base_date
and data_id
fields are empty. Here is a picture from the table:
How can I add the model_base_date
and data_id
when importing the shapefile into the table?