Developer Guide

The main philosophy of the package is to be able to reuse and / or extend all the models. To achieve this it is important to know that all UML classes are defined as abstract models in django and for instanciating a working model would must be as easy as inherit abstract models only.

Basic concepts

../_images/inspire_eu.svg

Customizating an existing theme

Following the above philosophy you can easily create/customize an existing theme.

If you want extend some fields in a particular model:

Differences between Original and Customizated

Django Inspire EU

My Awesome Project

inspire_eu.settings.py
INSPIRE_EU_THEMES = {
    # ...
    "cadastral_parcels": True,
    "buildings": True,
    # ...
}
my_awesome_proect.settings.py
 INSPIRE_EU_THEMES = {
     # ...
     "cadastral_parcels": False,
     "buildings": True,
     # ...
 }
inspire_eu.cadastral_parcels.models.__init.py__
if INSPIRE_EU_THEMES.get("cadastral_parcels"):
  from .abstract import AbstractCadastralZoning
  from .abstract import AbstractCadastralParcel







  class CadastralZoning(AbstractCadastralZoning,
                        models.Model)
    pass



class CadastralParcel(AbstractCadastralParcel,
                      models.Model):
  cadastral_zoning = models.ForeignKey(
        CadastralZoning, on_delete=models.PROTECT,
        blank=True, null=True
  )
my_awesome_app.models.__init.py__
from inspire_eu.models.abstract import (
  AbstractCadastralZoning, AbstractCadastralParcel
)
class AbstractCity(models.Model):
  city = models.CharField(max_length=64)

  class Meta:
    abstract = True


class CadastralZoning(AbstractCadastralZoning,
                      AbstractCity,
                      models.Model):
  pass


class AnotherExample(AbstractCadastralParcel,
                     AbstractCity,
                     models.Model):
  country = models.CharField(max_length=64)

Result:

  • CadastralZoning will add city field

  • AnotherExample will add city and country fields

  • Also will be available all Building models

Creating a new theme

Hint

To program a new theme you can see how the previous ones are made, even start doing copy & paste

  • Define all django models as abstract, in a new python module called abstract.py

  • Create a new entry in settings.INSPIRE_EU_THEMES with the default value True

  • In the __init__.py instantiate it -or not- depending on the value of the previous key

  • Check it out the inspire_eu.admin.__init__.py and add the new ones.