[GeoNode-users] How to establish a relation between a layer and a document in the GeoNode database

Eloi eloi at openmailbox.org
Wed Mar 8 05:09:18 PST 2017


Thanks for your quick reply Simone.

It was very helpful. Now I can see in a SQL query how Documents and 
Layers relate:

SELECT d.resourcebase_ptr_id AS doc_id,
        l.resourcebase_ptr_id AS lay_id,
        d.title_en AS doc_title,
        l.title_en AS lay_title
FROM documents_document AS d
LEFT JOIN layers_layer  AS l ON l.resourcebase_ptr_id = d.object_id
ORDER BY l.title_en;

And I was wrong when I said "every time I run the command "python 
manage.py updatelayers" all established relations (between a layers and 
a documents) disappear". That is not true, they did disappear because I 
have delete the layers in order to restore them again in the update. So 
my fault. Still learning.

Thank you very much for the help.

Cheers,

Eloi


On 2017-03-08 11:50, Simone Dalmasso wrote:

> Hi,
> 
> The layers are actually saved in the layer_layer table but the relation 
> is in document_document and points to the ContentType model. It is a 
> generic relation since it can point to any other geonode resource. The 
> two fields that you have to compile in the document table are the 
> contenty_type (the id if the layer content type in your case) and 
> object_id(the id of the target layer.)
> 
> Hope this helps
> 
> 2017-03-08 10:05 GMT+01:00 Eloi <eloi at openmailbox.org>:
> 
>> Good morning,
>> 
>> I would like to establish the relation between a layer and a document 
>> using the GeoNode database and not using the web interface.
>> I saw that the layers are listed in table 'base_resourcebase' and 
>> documents in 'documents_document'. So I wonder in which table the 
>> relation between the previous two is recorded. Then I would just run 
>> my SQL code to define does relations.
>> 
>> Why I want to do this? Because every time I run the command "python 
>> manage.py updatelayers" all established relations (between a layers 
>> and a documents) disappear.
>> 
>> Thank you in advance!
>> 
>> Cheers,
>> 
>> Eloi



More information about the geonode-users mailing list