Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 61bf27e

Browse files
author
Wes Kendall
committed
updated docs for BaseEntityModel change
1 parent 1b071b8 commit 61bf27e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ Imagine that you have a Django project that defines many types of groupings of y
1313
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).
1414

1515
## 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.
1717

18-
from django.db import models
19-
from entity import EntityModelMixin
18+
from entity import BaseEntityModel
2019

21-
class Account(models.Model, EntityModelMixin):
20+
class Account(BaseEntityModel):
2221
email = models.CharField(max_length=64)
2322

2423
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
4039
entity = Entity.objects.get(entity_type=ContentType.objects.get_for_model(Account), entity_id=account.id)
4140

4241
## 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.
4443

4544
- **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.
4645

@@ -54,9 +53,9 @@ Django entity provides the ability to model relationships of your entities to ot
5453
Let's start off with an example of two entities, an Account and a Group.
5554

5655
from django.db import models
57-
from entity import EntityModelMixin
56+
from entity import BaseEntityModel
5857

59-
class Group(models.Model, EntityModelMixin):
58+
class Group(BaseEntityModel):
6059
name = models.CharField(max_length=64)
6160

6261
def get_entity_meta(self):
@@ -65,7 +64,7 @@ Let's start off with an example of two entities, an Account and a Group.
6564
"""
6665
return {'name': self.name}
6766

68-
class Account(models.Model, EntityModelMixin):
67+
class Account(BaseEntityModel):
6968
email = models.CharField(max_length=64)
7069
group = models.ForeignKey(Group)
7170
is_active = models.BooleanField(default=True)

0 commit comments

Comments
 (0)