You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+7-8Lines changed: 7 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -13,12 +13,11 @@ Imagine that you have a Django project that defines many types of groupings of y
13
13
Using Django entity, the email app could be written to take an Entity model rather than having to understand the complex relationships of each group. The Entity model passed to the email app could be a CompanyPosition model, and the get_sub_entities(entity_type=ContentType.objects.get_for_model(User)) would return all of the User models under that CompanyPosition model. This allows the email app to be completely segregated from how the main project defines its relationships. Similarly, the query to obtain all User models under a CompanyPosition could be much more efficient than querying directly from the project (depending on how the project has its models structured).
14
14
15
15
## How Does It Work?
16
-
In order to sync entities and their relationships from your project to the Django entity table, you must first create a model that inherits DjangoEntityMixin.
16
+
In order to sync entities and their relationships from your project to the Django entity table, you must first create a model that inherits BaseEntityModel.
17
17
18
-
from django.db import models
19
-
from entity import EntityModelMixin
18
+
from entity import BaseEntityModel
20
19
21
-
class Account(models.Model, EntityModelMixin):
20
+
class Account(BaseEntityModel):
22
21
email = models.CharField(max_length=64)
23
22
24
23
When you update your models to inherit this mixin, they will automatically be synced to the Entity table when they are updated or deleted. The first time that you migrate a model in your application, you must remember to sync all of the entities so that the current ones get synced to the entity table. This can be accomplished with
@@ -40,7 +39,7 @@ After the entities have been synced, they can then be accessed in the primary En
## How Do I Specify Relationships And Additonal Metadata About My Entities?
43
-
Django entity provides the ability to model relationships of your entities to other entities. It also provides further capabilities for you to store additional metadata about your entities so that it can be quickly retrieved without having to access the main project tables. Here are additional functions defined in the EntityModelMixin that allow you to model your relationships and metadata. The next section describes how to query based on these relationships and retrieve the metadata in the Entity table.
42
+
Django entity provides the ability to model relationships of your entities to other entities. It also provides further capabilities for you to store additional metadata about your entities so that it can be quickly retrieved without having to access the main project tables. Here are additional functions defined in the BaseEntityModel that allow you to model your relationships and metadata. The next section describes how to query based on these relationships and retrieve the metadata in the Entity table.
44
43
45
44
-**get_entity_meta(self)**: Return a dictionary of any JSON-serializable data. This data will be serialized into JSON and stored as a string for later access by any application. This function provides your project with the ability to save application-specific data in the metadata that can later be retrieved or viewed without having to access the main project tables. Defaults to returning None.
46
45
@@ -54,9 +53,9 @@ Django entity provides the ability to model relationships of your entities to ot
54
53
Let's start off with an example of two entities, an Account and a Group.
55
54
56
55
from django.db import models
57
-
from entity import EntityModelMixin
56
+
from entity import BaseEntityModel
58
57
59
-
class Group(models.Model, EntityModelMixin):
58
+
class Group(BaseEntityModel):
60
59
name = models.CharField(max_length=64)
61
60
62
61
def get_entity_meta(self):
@@ -65,7 +64,7 @@ Let's start off with an example of two entities, an Account and a Group.
0 commit comments