<div dir="ltr"><div dir="ltr"><div>Hi List<br><br>I would like to programmatically create a map that consists of my base layers (all configured in settings.py) and an existing layer that I've added to geonode.<br><br>So, I have a workaround solution to do this using the manage.py dumpdata/loaddata commands. I've created my content manually, then dumped out the model configuration to JSON. Then cleaned my environment, i.e. deleted all the content, and then run ./manage.py loaddata config.json. This works, but it is not particularly robust as there are hardcoded primary key values for maps and layers in the JSON config.<br><br>I think it might be preferable to use the geonode python package. I saw that there's a method 'create_from_layer_list' in /maps/models.py. I think this is what I want, so I wrote a short custom management command to import the maps model and call this method:<br><br>>>>><br><br>from django.core.management.base import BaseCommand, CommandError<br>from django.contrib.auth import get_user_model<br>from geonode.maps.models import Map<br>from geonode.layers.models import Layer<br><br>class Command(BaseCommand):<br>    def handle(self, *args, **kwargs):<br>        m = Map()<br>        layer_name = Layer.objects.all().first().alternate<br>        admin_user = get_user_model().objects.get(username='admin')<br>        m.create_from_layer_list(admin_user, [layer_name], "test_map", "this is a map")<br><br>>>>><br><br>This custom command created a map object but is missing any of my base layers, so the map doesn't render any content.<br><br>Within the management command, I need to add the base layers as well, but am not sure of what to try next to solve this.<br><br>Is the "create_from_layer_list" method the best way to go, or is there a better way to programmatically generate a map based on a list of layers (other than my dumpdata/loaddata approach).<br><br>Thanks in advance for any advice.</div></div></div>