Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added table for sizzle time tracking project #2617

Merged
merged 8 commits into from
Aug 9, 2024
75 changes: 75 additions & 0 deletions website/migrations/0125_activitylog_timelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Generated by Django 5.0.7 on 2024-08-09 19:52

import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("website", "0124_company_tags_domain_tags_project_tags_and_more"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="ActivityLog",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("window_title", models.CharField(max_length=255)),
("url", models.URLField(blank=True, null=True)),
("recorded_at", models.DateTimeField(auto_now_add=True)),
(
"created",
models.DateTimeField(default=django.utils.timezone.now, editable=False),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="activity_logs",
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.CreateModel(
name="TimeLog",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("start_time", models.DateTimeField()),
("end_time", models.DateTimeField(blank=True, null=True)),
("duration", models.DurationField(blank=True, null=True)),
("github_issue_url", models.URLField(blank=True, null=True)),
(
"created",
models.DateTimeField(default=django.utils.timezone.now, editable=False),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="timelogs",
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
32 changes: 32 additions & 0 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,3 +786,35 @@ class BaconToken(models.Model):

def __str__(self):
return f"{self.user.username} - {self.amount} BACON"


class TimeLog(models.Model):
user = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="timelogs"
)
start_time = models.DateTimeField()
end_time = models.DateTimeField(null=True, blank=True)
duration = models.DurationField(null=True, blank=True)
github_issue_url = models.URLField(null=True, blank=True) # URL field for GitHub issue
created = models.DateTimeField(default=timezone.now, editable=False)

def save(self, *args, **kwargs):
if self.end_time and self.start_time <= self.end_time:
self.duration = self.end_time - self.start_time
super().save(*args, **kwargs)

def __str__(self):
return f"TimeLog by {self.user.username} from {self.start_time} to {self.end_time}"


class ActivityLog(models.Model):
user = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="activity_logs"
)
window_title = models.CharField(max_length=255)
url = models.URLField(null=True, blank=True) # URL field for activity-related URL
recorded_at = models.DateTimeField(auto_now_add=True)
created = models.DateTimeField(default=timezone.now, editable=False)

def __str__(self):
return f"ActivityLog by {self.user.username} at {self.recorded_at}"
Loading