preferences/apps/crud/models.py
2024-07-29 17:22:56 +03:30

26 lines
817 B
Python

from django.db import models
from apps.gooyal_oauth2.models import Application
from apps.users.models import User
class Plan(models.Model):
application = models.ForeignKey(Application, on_delete=models.PROTECT)
client_id = models.CharField(max_length=255, null=True, blank=True)
owner = models.ForeignKey(User, on_delete=models.PROTECT, null=True, blank=True)
record_count = models.IntegerField(default=0)
record_limit = models.IntegerField(default=0)
class Data(models.Model):
user = models.ForeignKey(User, on_delete=models.PROTECT)
plan = models.ForeignKey(Plan, on_delete=models.PROTECT)
data = models.JSONField(default=dict)
@property
def application(self):
return str(self.plan.application.uuid)
class Meta:
unique_together = ('user', 'plan')