Digital Product Passport (DPP)#

Digital Product Passport (DPP) is a European initiative that seeks to improve the circular economy by optimizing the design, manufacture, and use of products. This initiative consists of collecting and disseminating information on products during the different stages of their life cycle.

In this example, we show how from a plantUML model (which describes a reduced DPP domain) it is possible to obtain a B-UML model, serialize it, and use it as input to our Django code generator to produce the model layer code of a Django web application.

The PlantUML model (code and graphic representation) that describes the domain is as follows. Copy this code into a new file and store it as dpp.plantuml.

 1@startuml
 2class ProductPassport{
 3  + code: str
 4  + product_name: int
 5  + brand: str
 6}
 7
 8class LifecycleStage{
 9  + start: date
10  + end: date 
11}
12
13class Design extends LifecycleStage {
14}
15
16class Use extends LifecycleStage {
17}
18
19class Manufacture extends LifecycleStage {
20}
21
22class Distribution extends LifecycleStage {
23}
24
25class RawMaterial {
26  + name: str
27}
28
29class Reparation {
30  + description: str
31  + date_set: date
32}
33
34ProductPassport "*" --> "1..*" LifecycleStage: stage
35LifecycleStage "*" --> "1..*" RawMaterial: composition
36Use "1" --> "*" Reparation: reparations
37
38@enduml
DPP model

To transform this PlantUML model to B-UML and use the Django code generator, you can run the following code.

 1from besser.BUML.notations.structuralPlantUML import plantuml_to_buml
 2from besser.BUML.metamodel.structural import DomainModel
 3from besser.generators.django import DjangoGenerator
 4
 5# PlantUML to B-UML model
 6dpp_buml: DomainModel = plantuml_to_buml(plantUML_model_path='dpp.plantuml')
 7
 8# Code Generation
 9django = DjangoGenerator(model=dpp_buml)
10django.generate()

The generated code for the model layer of the Django application will be stored in the output/models.py file. Additionally, the code to define the B-UML model is generated in buml/buml_model (this code can be used if you want to modify your model directly from the base code).

Now you can create your Django application and use the generated code. Below is the admin panel of a Django web application that uses the code generated for the data layer or model layer.

DPP model