loefsys.users.models.membership module

Module defining the Loefbijter membership model.

class loefsys.users.models.membership.Membership(*args, **kwargs)

Bases: Model

Model defining a person’s membership of Loefbijter.

Over the course of a member’s presence at Loefbijter, their membership status may change. For example, an active member may become a passive member, or an exceptional member becomes alumnus. This model exists to keep a record of those statuses and status changes.

This also means that a person’s membership period with one status may not overlap with a period of another membership status. When a person’s membership status changes, the record of that status ends on day X and the record of the next status starts on the next day, day X+1. Validation logic is in place to ensure this integrity.

member

The person that this membership belongs to.

Type:

LoefbijterMember

membership_type

The type of membership.

Type:

MembershipTypes

start

The start date of the person’s membership.

Type:

date

end

The end date of the person’s membership, if it exists.

Type:

date or None

member

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

membership_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

end

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

clean()

Run validation on the model.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

get_membership_type_display(*, field=<django.db.models.fields.PositiveSmallIntegerField: membership_type>)
get_next_by_start(*, field=<django.db.models.fields.DateField: start>, is_next=True, **kwargs)
get_previous_by_start(*, field=<django.db.models.fields.DateField: start>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

member_id
objects = <django.db.models.manager.Manager object>
loefsys.users.models.membership.validate_has_overlap(to_check: Membership, memberships: Iterable[Membership]) bool

Ensure non-overlapping memberships.

It checks the date range of the updated membership and compares it to existing memberships for the given user. Overlap exists when the end date of one membership is equal to or later than the start date of another.

Parameters:
  • to_check (Membership) – The updated membership.

  • memberships (Iterable of Membership) – The set of memberships belonging to the user.

Returns:

True if overlap exists and False if no overlap exists.

Return type:

bool