<commit_before>Monitored Models
================

.. highlight:: python

Enable model monitoring
^^^^^^^^^^^^^^^^^^^^^^^

If you want a model to be automaticaly monitored you can inherit from
these base models that create events via signals for all the inherited
monitored models.

``MonitoredModel`` : records any instance creation and deletion:

::

   python from mqueue.models import MonitoredModel

   #for an existing model replace class MyModel(models.Model) by this:
   class MyModel(MonitoredModel): 
      # ...

To record also every save of a model instance replace ``MonitoredModel``
by ``HighlyMonitoredModel``.

Note: for these no migration is needed for an existing model,
just plug and play.

``ObjectLevelMonitoredModel`` : this one needs a migration as it adds a``monitoring_level`` 
field to the model. Any instance can be set to a
monitoring level via the value of this field: ``0`` is no monitoring
(default), ``1`` records create and delete, ``2`` records also saves.

Switch off model monitoring
^^^^^^^^^^^^^^^^^^^^^^^^^^^

If later on you want to switch off monitoring for some models
add a setting ``MQUEUE_STOP_MONITORING`` with the class names of the
models:

::

   python MQUEUE_STOP_MONITORING = ['Model1', 'Model2']<commit_msg>ObjectLevelMontoringModel doc<commit_after>Monitored Models
================

.. highlight:: python

Enable model monitoring
^^^^^^^^^^^^^^^^^^^^^^^

Basic monitoring
~~~~~~~~~~~~~~~~

If you want a model to be automaticaly monitored you can inherit from
these base models that create events via signals for all the inherited
monitored models.

``MonitoredModel`` : records any instance creation and deletion:

::

   python from mqueue.models import MonitoredModel

   #for an existing model replace class MyModel(models.Model) by this:
   class MyModel(MonitoredModel): 
      # ...

To record also every save of a model instance replace ``MonitoredModel``
by ``HighlyMonitoredModel``.

Note: for these no migration is needed for an existing model,
just plug and play.

Object level monitoring
~~~~~~~~~~~~~~~~~~~~~~~

``ObjectLevelMonitoredModel`` : this one needs a migration as it adds a ``monitoring_level`` 
field to the model. Any instance can be set to a
monitoring level via the value of this field: ``0`` is no monitoring
(default), ``1`` records create and delete, ``2`` records also saves. 

Ex: let's say you have a page management app and you want to monitor only certain pages:

::

   # models.py
   python from mqueue.models import MonitoredModel

   class Page(ObjectLevelMonitoredModel): 
      # ...
      
   # admin.py
   from django.contrib import admin
   
   @admin.register(Page)
   class PageAdmin(admin.ModelAdmin):
   	# ...
   	def get_fieldsets(self, request, obj=None):
   		fieldsets = super(PageAdmin, self).get_fieldsets(request, obj)
   		#~ if we want only the superusers to be able to see the monitoring field in admin
   		if request.user.is_superuser:
   			fieldsets += ( 'Monitoring', {'fields': ('monitoring_level',)} ),
   		return fieldsets

Switch off model monitoring
^^^^^^^^^^^^^^^^^^^^^^^^^^^

If later on you want to switch off monitoring for some models
add a setting ``MQUEUE_STOP_MONITORING`` with the class names of the
models:

::
   
   # settings.py
   MQUEUE_STOP_MONITORING = ['Model1', 'Model2']
{'fraction_non_alphanumeric': 0.12303980699638119, 'fraction_numerical': 0.0030156815440289505, 'mean_word_length': 4.35, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6488422', 'n_tokens_mistral': 946, 'n_tokens_neox': 901, 'n_words': 389}