calingen.models
¶
Calingen’s implementations of django.db.models.Model
.
In the context of a Django application, models
define the app’s core data,
that is persisted in a database layer (abstracted by DJango’s ORM).
This package also includes model-related implementations of
django.db.models.QuerySet
, django.db.models.Manager
and
django.forms.ModelForm
.
Notes
It’s kind of recommended to have fat models in a Django application, that handle most of the app’s business logic.
However, fat models might lead to models, that are too tightly connected to each other.
Calingen’s models aim to present and manage the app’s data and enable working with that data.
Submodules¶
Package Contents¶
Classes¶
Represents one event in a user's calendar. |
|
Represents the app-specific profile. |
- class calingen.models.Event(*args, **kwargs)¶
Bases:
django.db.models.Model
Represents one event in a user’s calendar.
Warning
The class documentation only includes code that is actually shipped by the calingen app. Inherited attributes/methods (provided by Django’s
Model
) are not documented here.- class Meta¶
- app_label = calingen¶
- unique_together = ['profile', 'title', 'start']¶
- verbose_name¶
- verbose_name_plural¶
- calingen_manager¶
App-/model-specific manager, that provides additional functionality.
This manager is set to
calingen.models.event.EventManager
. Its implementation provides augmentations of Event objects, by annotating them on database level. This will reduce the number of required database queries, if attributes of the object are accessed.The manager has to be used explicitly.
- category¶
The category of this Event.
Notes
Some functionalities of the Event class depend on the actual
EventCategory
stored in this attribute.The attribute is implemented as
CharField
with its possible values limited bycalingen.constants.EventCategory
.
- objects¶
The model’s default manager.
The default manager is set to
django.db.models.Manager
, which is the default value. In order to add the customcalingen_manager
as an additional manager, the default manager has to be provided explicitly (see topics/db/managers/#default-managers).
- profile¶
Reference to a
Profile
object.Notes
This is implemented as a
ForeignKey
withon_delete=CASCADE
, meaning: if the referencedProfile
object is deleted, all referencingEvent
objects are discarded aswell.The backwards relation (see
ForeignKey.related_name
) is named"events"
.
- start¶
Date and time of a recurring event (
datetime.datetime
).Warning
The name of this attribute might be misleading at first. calingen will be developed in small steps, of which the first one will be to track annual aniversaries with the Event class. Nevertheless, it is planned to enable calingen to track generic recurring events. In that implementation step, Event instances will have a start and end
datetime
.To ease the refactoring, this attribute is already named start.
Notes
The attribute is implemented as
DateTimeField
.
- __str__()¶
Return str(self).
- get_absolute_url()¶
Return the absolute URL for instances of this model.
- Returns:
The absolute URL for instances of this model.
- Return type:
- class calingen.models.Profile(*args, **kwargs)¶
Bases:
django.db.models.Model
Represents the app-specific profile.
Warning
The class documentation only includes code that is actually shipped by the calingen app. Inherited attributes/methods (provided by Django’s
Model
) are not documented here.- property event_provider¶
Get and set the list of
EventProvider
.This method is used to access the
Profile
’sEventProvider
. The returned object will have three attributes,active
,unavailable
andnewly_unavailable
:active
contains the selectedEventProvider
plugins, that are currently active in this project. If the user had selectedEventProvider
plugins, that are currently not available in this project, i.e. because they were deactivated by the administrator, these plugins are moved tounavailable
. Also, these plugins are included innewly_unavailable
and then picked up in theget_context_data()
method to provide messages to the user.Notes
While the implementation of the
getter
involves some logic to perform the operations as described above, thesetter
simply applies the provided value to_event_provider
. This means, that if the user did not actually update its profile, the operation performed by thegetter
is simply discarded.
- _event_provider¶
Manage
EventProvider
plugins for this profile.Notes
This is implemented as a
JSONField
and should be interfaced by its customevent_provider()
getter and setter methods, provided as aproperty
.
- calingen_manager¶
App-/model-specific manager, that provides additional functionality.
This manager is set to
calingen.models.profile.ProfileManager
. Its implementation provides augmentations of Profile objects, by annotating them on database level. This will reduce the number of required database queries, if attributes of the object are accessed.The manager has to be used explicitly.
- objects¶
The model’s default manager.
The default manager is set to
django.db.models.Manager
, which is the default value. In order to add the customcalingen_manager
as an additional manager, the default manager has to be provided explicitly (see topics/db/managers/#default-managers).
- owner¶
Reference to a Django User.
Notes
This is implemented as a
OneToOneField
withon_delete=CASCADE
, meaning: if the referenced User object is deleted, the referencing Profile object is discarded aswell.To keep this application as pluggable as possible, the referenced class is dependent on
AUTH_USER_MODEL
. With this implementation, the project may substitute theUser
model provided by Django without breaking any functionality in calingen (see Reusable Apps and AUTH_USER_MODEL).
- __str__()¶
Return str(self).
- get_absolute_url()¶
Return the absolute URL for instances of this model.
- Returns:
The absolute URL for instances of this model.
- Return type:
- resolve(year=None)¶
Combine all event providers results for a given year into one
CalendarEntryList
.- Parameters:
year (int, optional) – The year to use for resolving the
EventProvider
.- Returns:
A single instance including all events from all active providers.
- Return type: