I currently have a project that consists of multiple webmaps that are written as different apps in a GeoDjango project. The structure of the project is as such:

- project
  - manage.py
  - project
    - settings.py, urls.py, views.py, etc.
  - app1
    - templates, models.py, load.py, urls.py, views.py, etc.
  - app2
    - templates, models.py, load.py, urls.py, views.py, etc.
  - appX
    - templates, models.py, etc.

Each of the apps are focused on particular geographic regions, and are uniquely accessible to members from those regions (e.g., cities within a state) and I don't want to collapse them all into one app. That said, they all use the same raster datasets. At present, new raster tables are built for each app in the app-specific models.py file, and the raster data is split across these tables in the database.

I think it is more efficient to have a project level table that houses all of the raster data -- but am not sure how to do so.

So, rather than having app1_raster, app2_raster, appx_raster tables, I would just have a raster table that all three apps access.

How do I create a project level database table? From what I've seen, documentation encourages one not to do so.

1 Answer 1


Apps are usually divided for different functionality and not per geographic regions. An example data model could be:

class Zone(models.Model):
    name = models.CharField(...)
    # ... other fields ...

class Placemark(modelf.Model):
    zone = models.ForeignKey(Zone, related_name='placemarks', ...)
    geom = PointField()
    # .... other fields ....

This allows having many zones using one simple code base. Querying for a zone's placemarks is easy as:

# assuming:
my_zone = Zone.objects.get(id=123)
# get the placemarks:
placemarks = my_zone.placemarks.all()

To add rasters-per-zone use

class Raster(modelf.Model):
    zone = models.ForeignKey(Zone, related_name='rasters', ...)
    # .... raster specific other fields ....

This model can be in a rasters app that holds raster-specific functionality.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.