GeoNode / geonode-project

A django template project for creating custom GeoNode projects.
http://geonode.org
77 stars 171 forks source link

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

Open eruiz67 opened 1 year ago

eruiz67 commented 1 year ago

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)