diff --git a/apps/crud/migrations/0003_alter_plan_owner.py b/apps/crud/migrations/0003_alter_plan_owner.py new file mode 100644 index 0000000..e99beed --- /dev/null +++ b/apps/crud/migrations/0003_alter_plan_owner.py @@ -0,0 +1,21 @@ +# Generated by Django 5.0.6 on 2024-07-29 13:42 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('crud', '0002_plan_client_id_alter_data_unique_together'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AlterField( + model_name='plan', + name='owner', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/apps/crud/models.py b/apps/crud/models.py index 8d83bbf..dca725f 100644 --- a/apps/crud/models.py +++ b/apps/crud/models.py @@ -6,7 +6,7 @@ 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) + owner = models.ForeignKey(User, on_delete=models.PROTECT, null=True, blank=True) record_count = models.IntegerField(default=0) record_limit = models.IntegerField(default=0) diff --git a/apps/crud/views.py b/apps/crud/views.py index 0484382..941cc3f 100644 --- a/apps/crud/views.py +++ b/apps/crud/views.py @@ -29,7 +29,9 @@ class DataViewSet(mixins.RetrieveModelMixin, user = self.request.user auth = self.request.auth if auth: - plan = Plan.objects.filter(application_id=auth.application_id).first() + # plan = Plan.objects.filter(application_id=auth.application_id).first() + plan, created = Plan.objects.get_or_create(application_id=auth.application_id) + # data, created = Data.objects.get_or_create(plan_id=plan.pk, user=user) data, created = Data.objects.get_or_create(plan_id=plan.pk, user=user) return data