Files
abyssVpn/services/api/vpn/models.py
T
arthur_chen f69efb67ad Initial commit: abyssVpn project
- Tauri desktop app (apps/desktop)
- Python Django API service (services/api)
- Deployment scripts and docs
2026-05-15 09:06:10 +08:00

36 lines
1.2 KiB
Python

from django.db import models
from accounts.models import User
class Device(models.Model):
STATUS_ACTIVE = "active"
STATUS_REVOKED = "revoked"
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="devices")
device_name = models.CharField(max_length=128)
device_fingerprint = models.CharField(max_length=256, blank=True)
netmaker_node_id = models.CharField(max_length=128, blank=True)
status = models.CharField(max_length=16, default=STATUS_ACTIVE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self) -> str:
return f"{self.user_id}:{self.device_name}"
class Meta:
constraints = [
models.UniqueConstraint(
fields=["user", "device_fingerprint"],
name="unique_user_device_fingerprint",
)
]
class VpnLog(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
device = models.ForeignKey(Device, on_delete=models.SET_NULL, null=True, blank=True)
action = models.CharField(max_length=64)
detail = models.JSONField(default=dict, blank=True)
created_at = models.DateTimeField(auto_now_add=True)