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, null=True, blank=True) plan = models.ForeignKey(Plan, on_delete=models.PROTECT, null=True, blank=True) data = models.JSONField(default=dict) @property def application(self): return str(self.plan.application.uuid) class Meta: unique_together = ('user', 'plan')