Django Generator

This module generates Django code using Jinja2 templates based on BUML models.

class besser.generators.django.django_generator.DjangoGenerator(model: DomainModel, project_name: str, app_name: str, gui_model: GUIModel = None, containerization: bool = False, module: Module = None, output_dir: str = None)[source]

Bases: GeneratorInterface

DjangoGenerator is responsible for generating Django executable code based on input B-UML and GUI models. It implements the GeneratorInterface and facilitates the creation of a Django web application structure.

Parameters:
  • model (DomainModel) – The B-UML model representing the application’s domain.

  • project_name (str) – The name of the Django project.

  • app_name (str) – The name of the Django application.

  • gui_model (GUIModel) – The GUI model instance containing necessary configurations.

  • main_page (Screen) – The main page of the web application.

  • containerization (bool, optional) – Whether to enable containerization

  • support. Defaults to False.

  • module (Module, optional) – Represents a specific module within the application, typically grouping related screens and functionalities.

  • output_dir (str, optional) – Directory where generated code will be saved. Defaults to None.

property gui_model : GUIModel

Get the instance of the GUIModel class representing the GUI model.

Type:

GUIModel

property module : Module

Get the instance of the Module class representing the module of the Django application.

Type:

Module

_base_dir() → str[source]

Absolute directory anchoring every filesystem effect of this generator.

The whole generated project tree is placed under this directory, regardless of the caller’s current working directory. When no output_dir was provided, it falls back to the caller’s working directory, preserving the historical default layout (<cwd>/<project_name>).

_project_dir() → str[source]

Absolute path of the generated Django project directory.

_app_dir() → str[source]

Absolute path of the generated Django app directory.

_templates_dir() → str[source]

Absolute path of the app templates directory (created on demand).

static is_button(value)[source]

Check if the given value is an instance of Button class.

static is_list(value)[source]

Check if the given value is an instance of DataList class.

static is_model_element(value)[source]

Check if the given value is an instance of DataSourceElement class.

static is_primitive_data_type(value)[source]

Check if the given value is an instance of PrimitiveDataType class.

static is_enumeration(value)[source]

Check if the given value is an instance of Enumeration class.

generate_models()[source]

Generates Django models code based on the provided B-UML model and saves it to the specified output directory. If the output directory was not specified, the code generated will be stored in the <current directory>/output folder.

Returns:

None, but stores the generated code as a file named models.py.

generate_urls()[source]

Generates the Django URLs file for a web application based on the provided B-UML and GUI models and saves it to the specified output directory. If the output directory was not specified, the code generated will be stored in the <current directory>/output folder.

Returns:

None, but stores the generated code as a file named urls.py.

generate_forms(one_to_one, many_to_many, fkeys)[source]

Generates the Django Forms file for a web application based on the provided B-UML and GUI models and saves it to the specified output directory. If the output directory was not specified, the code generated will be stored in the <current directory>/output folder.

Returns:

None, but stores the generated code as a file named forms.py.

generate_views()[source]

Generates the Django views file for a web application based on the provided B-UML and GUI models and saves it to the specified output directory. If the output directory was not specified, the code generated will be stored in the <current directory>/output folder.

Returns:

None, but stores the generated code as a file named views.py.

generate_home_page()[source]

Generates the Home Page Template code for a Django application based on the provided GUI model and saves it to the specified output directory. If the output directory was not specified, the code generated will be stored in the <current directory>/output folder.

Returns:

None, but stores the generated code as a file named main.dart.

generate_base_pages()[source]

Generate HTML files for each screen in the module, using a Jinja template. Each HTML file is saved in the output directory, named based on the screen’s name.

generate_list_html_pages(one_to_one, many_to_many, fkeys)[source]

Generate List HTML files for each screen in the module, using a Jinja template. Each HTML file is saved in the output directory, named based on the screen’s name_list.

generate_form_html_pages(one_to_one, many_to_many, fkeys)[source]

Generate HTML files for each screen in the module, using a Jinja template. Each HTML file is saved in the output directory, named based on the screen’s name_form.

_abc_impl = <_abc._abc_data object>
generate_project_urls()[source]

Generates the Django project URLs file based on the provided GUI model and saves it to the specified output directory. If the output directory was not specified, the code generated will be stored in the <current directory>/output folder.

Returns:

None, but stores the generated code as a file named project_urls.py.

create_file_from_template(template_name, output_name)[source]

Create a file from a Jinja2 template.

update_settings()[source]

Update the configuration in settings.py.

generate(*args)[source]

Generates the Django project, app, and necessary configurations.