非类写法参照下移

This commit is contained in:
2025-11-15 12:12:09 +08:00
parent 3a0e3e9ad1
commit 16469920ae
10 changed files with 118 additions and 53 deletions

0
myapp_api/__init__.py Normal file
View File

3
myapp_api/admin.py Normal file
View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
myapp_api/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class MyappApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'myapp_api'

View File

@@ -0,0 +1,24 @@
# Generated by Django 5.2.8 on 2025-11-15 03:44
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('city', models.CharField(max_length=100)),
('sex', models.CharField(max_length=100)),
('age', models.IntegerField()),
],
),
]

View File

8
myapp_api/models.py Normal file
View File

@@ -0,0 +1,8 @@
from django.db import models
# Create your models here.
class User(models.Model):
name = models.CharField(max_length=100)
city = models.CharField(max_length=100)
sex = models.CharField(max_length=100)
age = models.IntegerField()

3
myapp_api/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

7
myapp_api/views.py Normal file
View File

@@ -0,0 +1,7 @@
from rest_framework import viewsets
from .serializers import UserSerializer
from myapp_api.models import User
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all() # 指定操作的数据
serializer_class = UserSerializer # 指定序列化器