sample api work
This commit is contained in:
parent
b6a57bfc65
commit
f21f156127
3 changed files with 25 additions and 2 deletions
21
apps/crud/migrations/0003_alter_plan_owner.py
Normal file
21
apps/crud/migrations/0003_alter_plan_owner.py
Normal file
|
|
@ -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),
|
||||
),
|
||||
]
|
||||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue