luanpoppe commited on
Commit
6299b99
·
1 Parent(s): b34386c

adicionando banco de dados

Browse files
endpoint_teste/migrations/0001_initial.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generated by Django 4.1 on 2024-11-09 22:42
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ initial = True
9
+
10
+ dependencies = [
11
+ ]
12
+
13
+ operations = [
14
+ migrations.CreateModel(
15
+ name='EndpointTesteModel',
16
+ fields=[
17
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18
+ ('teste', models.CharField(max_length=300)),
19
+ ],
20
+ ),
21
+ ]
modelos_usuarios/__init__.py ADDED
File without changes
modelos_usuarios/admin.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.contrib import admin
2
+
3
+ # Register your models here.
modelos_usuarios/apps.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class ModelosUsuariosConfig(AppConfig):
5
+ default_auto_field = 'django.db.models.BigAutoField'
6
+ name = 'modelos_usuarios'
modelos_usuarios/migrations/0001_initial.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generated by Django 4.1 on 2024-11-09 22:49
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ initial = True
9
+
10
+ dependencies = [
11
+ ]
12
+
13
+ operations = [
14
+ migrations.CreateModel(
15
+ name='ModeloUsuarioModel',
16
+ fields=[
17
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18
+ ('user_id', models.IntegerField()),
19
+ ('modelo', models.TextField()),
20
+ ],
21
+ ),
22
+ ]
modelos_usuarios/migrations/__init__.py ADDED
File without changes
modelos_usuarios/models.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ from django.db import models
2
+
3
+ class ModeloUsuarioModel(models.Model):
4
+ user_id = models.IntegerField()
5
+ modelo = models.TextField()
modelos_usuarios/serializer.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from rest_framework import serializers
2
+ from modelos_usuarios.models import ModeloUsuarioModel
3
+
4
+ class ModeloUsuarioSerializer(serializers.ModelSerializer):
5
+ class Meta:
6
+ model = ModeloUsuarioModel
7
+ fields = "__all__"
modelos_usuarios/tests.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.test import TestCase
2
+
3
+ # Create your tests here.
modelos_usuarios/views.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from rest_framework.views import APIView
2
+ from rest_framework.response import Response
3
+ from modelos_usuarios.models import ModeloUsuarioModel
4
+ from modelos_usuarios.serializer import ModeloUsuarioSerializer
5
+
6
+ class ListCreateModeloUsuarioView(APIView):
7
+ def get(self, request):
8
+ all = ModeloUsuarioModel.objects.all()
9
+ print("\n\n\n")
10
+ print(all)
11
+ return Response(all)
12
+
13
+ def post(self, request):
14
+ serializer = ModeloUsuarioSerializer(data=request.data)
15
+ if serializer.is_valid():
16
+ registro = ModeloUsuarioModel.objects.create(**serializer.validated_data)
17
+ return Response(registro.data)