-
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.
- Loading branch information
Showing
5 changed files
with
127 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Admin for the example project.""" | ||
|
||
from django.contrib import admin | ||
|
||
from .models import EventSegment | ||
from .models import EventSpan | ||
|
||
|
||
@admin.register(EventSpan) | ||
class EventSpanAdmin(admin.ModelAdmin): | ||
"""Admin for EventSpan model.""" | ||
|
||
list_display = ("id", "initial_range", "current_range", "deleted_at") | ||
search_fields = ("id",) | ||
|
||
|
||
@admin.register(EventSegment) | ||
class EventSegmentAdmin(admin.ModelAdmin): | ||
"""Admin for EventSegment model.""" | ||
|
||
list_display = ("id", "segment_range", "event_span", "previous_segment", "deleted_at") | ||
search_fields = ("id",) |
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,10 +1,18 @@ | ||
"""Example app config.""" | ||
|
||
import logging | ||
|
||
from django.apps import AppConfig | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ExampleConfig(AppConfig): | ||
"""Example app config.""" | ||
|
||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "example_project.example" | ||
|
||
def ready(self): | ||
logger.debug("Initializing example app") |
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,74 @@ | ||
# Generated by Django 4.2.13 on 2024-05-25 18:01 | ||
|
||
import django.contrib.postgres.fields.ranges | ||
import django.db.models.deletion | ||
from django.db import migrations | ||
from django.db import models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="EventSpan", | ||
fields=[ | ||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
( | ||
"deleted_at", | ||
models.DateTimeField( | ||
blank=True, | ||
help_text="The date and time the span was deleted.", | ||
null=True, | ||
verbose_name="Deleted at", | ||
), | ||
), | ||
("initial_range", django.contrib.postgres.fields.ranges.DateTimeRangeField()), | ||
("current_range", django.contrib.postgres.fields.ranges.DateTimeRangeField()), | ||
], | ||
options={ | ||
"abstract": False, | ||
"indexes": [ | ||
models.Index(fields=["initial_range"], name="example_eve_initial_ea4530_idx"), | ||
models.Index(fields=["current_range"], name="example_eve_current_caa1f9_idx"), | ||
models.Index(fields=["deleted_at"], name="example_eve_deleted_fb1e91_idx"), | ||
], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="EventSegment", | ||
fields=[ | ||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
( | ||
"deleted_at", | ||
models.DateTimeField( | ||
blank=True, | ||
help_text="The date and time the segment was deleted.", | ||
null=True, | ||
verbose_name="Deleted at", | ||
), | ||
), | ||
("segment_range", django.contrib.postgres.fields.ranges.DateTimeRangeField()), | ||
("event_span", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="example.eventspan")), | ||
( | ||
"previous_segment", | ||
models.OneToOneField( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="next_segment", | ||
to="example.eventsegment", | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
"indexes": [ | ||
models.Index(fields=["segment_range"], name="example_eve_segment_8531e0_idx"), | ||
models.Index(fields=["deleted_at"], name="example_eve_deleted_b015b4_idx"), | ||
], | ||
}, | ||
), | ||
] |
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,36 +1,35 @@ | ||
# """Models for the example app.""" | ||
"""Models for the example app.""" | ||
|
||
# from django.contrib.postgres.fields import DateTimeRangeField | ||
# from django.db import models | ||
from django.contrib.postgres.fields import DateTimeRangeField | ||
from django.db import models | ||
|
||
# from django_segments.models import AbstractSegment | ||
# from django_segments.models import AbstractSpan | ||
from django_segments.models import AbstractSegment | ||
from django_segments.models import AbstractSpan | ||
|
||
|
||
# class EventSpan(AbstractSpan): | ||
# """A span of time that contains event segments.""" | ||
class EventSpan(AbstractSpan): | ||
"""A span of time that contains event segments.""" | ||
|
||
# initial_range = DateTimeRangeField() | ||
# current_range = DateTimeRangeField() | ||
initial_range = DateTimeRangeField() | ||
current_range = DateTimeRangeField() | ||
|
||
# class Meta: # pylint: disable=missing-class-docstring | ||
# abstract = False | ||
# class Meta: # pylint: disable=missing-class-docstring | ||
# abstract = False | ||
|
||
# def __str__(self): | ||
# return f"Initial: {self.initial_range} - Current: {self.current_range}" | ||
def __str__(self): | ||
return f"Initial: {self.initial_range} - Current: {self.current_range}" | ||
|
||
|
||
# class EventSegment(AbstractSegment): | ||
# """A segment of time within an event span.""" | ||
class EventSegment(AbstractSegment): | ||
"""A segment of time within an event span.""" | ||
|
||
# event_span = models.ForeignKey(EventSpan, on_delete=models.CASCADE) | ||
# segment_range = DateTimeRangeField() | ||
event_span = models.ForeignKey("EventSpan", on_delete=models.CASCADE) | ||
segment_span_field_name = "event_span" | ||
|
||
# # If a field name other than `segment_range` is used for the range field, it should be specified like this: | ||
# segment_range_field = "segment_range" | ||
segment_range = DateTimeRangeField() | ||
|
||
# class Meta: # pylint: disable=missing-class-docstring | ||
# abstract = False | ||
# class Meta: # pylint: disable=missing-class-docstring | ||
# abstract = False | ||
|
||
# def __str__(self): | ||
# return f"Segment Range: {self.segment_range}" | ||
def __str__(self): | ||
return f"Segment Range: {self.segment_range}" |
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