forked from mongodb-labs/django-mongodb-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent the creation of embedded models
- Loading branch information
Showing
16 changed files
with
236 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
from django.db import NotSupportedError | ||
from django.db.models.manager import BaseManager | ||
|
||
from .queryset import MongoQuerySet | ||
|
||
|
||
class MongoManager(BaseManager.from_queryset(MongoQuerySet)): | ||
pass | ||
|
||
|
||
class EmbeddedModelManager(BaseManager): | ||
""" | ||
Prevent all queryset operations on embedded models since they don't have | ||
their own collection. | ||
Raise a helpful error message for some basic QuerySet methods. Subclassing | ||
BaseManager means that other methods raise, e.g. AttributeError: | ||
'EmbeddedModelManager' object has no attribute 'update_or_create'". | ||
""" | ||
|
||
def all(self): | ||
raise NotSupportedError("EmbeddedModels cannot be queried.") | ||
|
||
def get(self, *args, **kwargs): | ||
raise NotSupportedError("EmbeddedModels cannot be queried.") | ||
|
||
def filter(self, *args, **kwargs): | ||
raise NotSupportedError("EmbeddedModels cannot be queried.") | ||
|
||
def create(self, **kwargs): | ||
raise NotSupportedError("EmbeddedModels cannot be created.") | ||
|
||
def update(self, *args, **kwargs): | ||
raise NotSupportedError("EmbeddedModels cannot be updated.") | ||
|
||
def delete(self): | ||
raise NotSupportedError("EmbeddedModels cannot be deleted.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.db import NotSupportedError, models | ||
|
||
from .managers import EmbeddedModelManager | ||
|
||
|
||
class EmbeddedModel(models.Model): | ||
objects = EmbeddedModelManager() | ||
|
||
class Meta: | ||
abstract = True | ||
|
||
def delete(self, *args, **kwargs): | ||
raise NotSupportedError("EmbeddedModels cannot be deleted.") | ||
|
||
def save(self, *args, **kwargs): | ||
raise NotSupportedError("EmbeddedModels cannot be saved.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Model reference | ||
=============== | ||
|
||
.. module:: django_mongodb_backend.models | ||
|
||
One MongoDB-specific model is available in ``django_mongodb_backend.models``. | ||
|
||
.. class:: EmbeddedModel | ||
|
||
An abstract model which all :doc:`embedded models <embedded-models>` must | ||
subclass. | ||
|
||
Since these models are not stored in their own collection, they do not have | ||
any of the normal ``QuerySet`` methods (``all()``, ``filter()``, ``delete()``, | ||
etc.) You also cannot call ``Model.save()`` and ``delete()`` on them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django_mongodb_backend.models import EmbeddedModel | ||
|
||
|
||
class Embed(EmbeddedModel): | ||
pass |
Oops, something went wrong.