Skip to content

Extras

This section refers to the extras that Edgy offer and can be used in your application without incurring into extra overhead to make it happen.

If you are in this section, you surely read about the auto discovery and how it relates with the way Edgy handles and manages migrations for you.

But, what if you simply would like to use the shell or any related command offered by Edgy that doesn't necessarily requires migration management?

The Migrate object is the way of Edgy knowing what to do and how to manage your models but there are cases where that doesn't happen and it is not needed, for example, a project using reflect models.

A project using reflect models, means that somehow migrations are managed externally and not by Edgy and Edgy only needs to reflect those tables back into your code, so, do you really need the Migrate object here? Short answer is no.

So how can you still use those features without depending on the Migrate object? Enters EdgyExtra.

EdgyExtra

This is the object you want to use when you don't need Edgy to manage the migrations for you and yet still being able to use Edgy tools like the shell.

How does it work

Well, its actually very similar to Migrate object in terms of setup.

Let us use Esmerald again as an example like we did for the tips and tricks.

#!/usr/bin/env python
"""
Generated by 'esmerald createproject'
"""

import os
import sys
from pathlib import Path

from esmerald import Esmerald, Include

import edgy
from edgy import Database, EdgyExtra, Registry

database = Database("sqlite:///db.sqlite")
registry = Registry(database)


class CustomModel(edgy.Model):
    name: str = edgy.CharField(max_length=255)
    email: str = edgy.EmailField(max_length=255)

    class Meta:
        registry = registry


def build_path():
    """
    Builds the path of the project and project root.
    """
    Path(__file__).resolve().parent.parent
    SITE_ROOT = os.path.dirname(os.path.realpath(__file__))

    if SITE_ROOT not in sys.path:
        sys.path.append(SITE_ROOT)
        sys.path.append(os.path.join(SITE_ROOT, "apps"))


def get_application():
    """
    This is optional. The function is only used for organisation purposes.
    """

    app = Esmerald(
        routes=[Include(namespace="my_project.urls")],
    )

    EdgyExtra(app=app, registry=registry)
    return app


app = get_application()

And that is it, you can use any tool that does not relate with migrations in your application.

Warning

Be aware of the use of this special class in production! It is advised not to use it there.

Note

For now, besides the migrations and the shell, Edgy does not offer any extra tools but there are plans to add more extras in the future and EdgyExtra is the way to go for that setup.