创建模型
from django.conf import settings
from django.db.models import (
Model,
CharField,
TextField,
DateTimeField,
ForeignKey,
SET_NULL
)
class TestEnvironment(Model):
name = CharField(max_length=50, null=True, blank=True, verbose_name="测试环境名称")
user = ForeignKey(settings.AUTH_USER_MODEL, null=True, related_name="author", on_delete=SET_NULL, verbose_name='作者')
host_address = CharField(max_length=50, null=True, blank=True, verbose_name="环境地址")
desc = TextField(null=True, blank=True, verbose_name="环境描述")
create_time = DateTimeField(auto_now_add=True, verbose_name='创建时间')
update_time = DateTimeField(auto_now=True, verbose_name='更新时间')
class Meta:
verbose_name = '环境配置'
verbose_name_plural = verbose_name
ordering = ("create_time",)
def __str__(self):
return self.name
编写视图
class TestEnvironmentViewSet(viewsets.ModelViewSet):
queryset = TestEnvironment.objects.order_by('-create_time').all()
serializer_class = TestEnvironmentSerializers
1.注册、登录、第三方登录 (前后端)
2.单元测试代码编写