geonode-project icon indicating copy to clipboard operation
geonode-project copied to clipboard

How to create dataset from code and "inject" multipolygon to it?

Open eruiz67 opened this issue 2 years ago • 0 comments

I have created a new django app form my geonode-project In this app I have a Project Model with a geom (Multipolygon field), It also has a OneToOneField to Dataset. What I want to achieve is: 1 - When a Project is created a new dataset must be created showing the same multipolygon of the project. (Keep reference project-dataset through the dataset OneToOneField field) 2 - When the project geom field is updated, the dataset must update its geometry (Multipolygon) as well

I want to know which methods/functions I can use to create a new dataset and “inject” that multipolygon that is coming from project. I want to know how to update the dataset so it can show the new Multypolygon Here is my model definition:


from django.utils.translation import gettext_lazy as _
from django.conf import settings
from geonode.layers.models import Dataset
from django.contrib.gis.db import models 

class Project(models.Model):

    name = models.CharField(_("Nombre"), max_length=50, unique=True)

    geom = models.MultiPolygonField(verbose_name=_("Localización"), srid=4326, blank=True, null=True)
    
    dataset = models.OneToOneField(Dataset, verbose_name=_("Dataset"), on_delete=models.CASCADE,  related_name="proyecto", blank=True, null=True)

eruiz67 avatar Jan 14 '23 23:01 eruiz67