添加新的应用

master
roger 1 year ago
parent 2f83a3bd30
commit cac3d691cf
  1. 1
      django_demo/settings.py
  2. 0
      form_demo/__init__.py
  3. 3
      form_demo/admin.py
  4. 6
      form_demo/apps.py
  5. 25
      form_demo/forms.py
  6. 33
      form_demo/migrations/0001_initial.py
  7. 0
      form_demo/migrations/__init__.py
  8. 17
      form_demo/models.py
  9. 3
      form_demo/tests.py
  10. 3
      form_demo/views.py

@ -32,6 +32,7 @@ ALLOWED_HOSTS = []
INSTALLED_APPS = [
'orm_demo.apps.OrmDemoConfig',
'form_demo.apps.FormDemoConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',

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

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

@ -0,0 +1,25 @@
from django import forms
from django.core.exceptions import ValidationError
from models import *
def age_validate(age):
if age <= 0:
raise ValidationError('年龄错误')
elif age > 150:
raise ValidationError('老妖精')
# 用户信息表单
class UserInfoForm(forms.Form):
STATUS = ((None, '请选择'), (0, '正常'), (1, '无效'))
username = forms.CharField(label="用户名", min_length=6, widget=forms.widgets.TextInput(
attrs={'class': 'form-control', 'placeholder': '请输入用户名'}))
password = forms.CharField(label='密码', min_length=6, max_length=10,
widget=forms.widgets.PasswordInput(attrs={'class': 'password'}, render_value=True),
help_text='密码长度为6-10个字符')
age = forms.IntegerField(label='年龄', initial=1, min_value=1, max_value=150, validators=[age_validate])
mobile = forms.CharField(label='手机号码', min_length=11, max_length=11)
status = forms.ChoiceField(label='状态', choices=STATUS, widget=forms.widgets.Select)
# status = forms.ModelChoiceField(queryset=UserStatus.objects.all(), empty_label='请选择')
createdate = forms.DateField(label='创建日期', required=False, input_formats=["%Y-%m-%d"])

@ -0,0 +1,33 @@
# Generated by Django 4.2.3 on 2023-07-13 00:41
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='UserBaseInfo',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='用户id')),
('username', models.CharField(max_length=30, verbose_name='用户名')),
('password', models.CharField(max_length=20, verbose_name='密码')),
('age', models.IntegerField(verbose_name='年龄')),
('mobile', models.CharField(max_length=20, verbose_name='手机号')),
('status', models.CharField(max_length=1, verbose_name='状态')),
('create_date', models.DateField(auto_now_add=True, verbose_name='创建时间')),
],
),
migrations.CreateModel(
name='UserStatus',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='状态id')),
('status', models.CharField(max_length=10, verbose_name='状态')),
],
),
]

@ -0,0 +1,17 @@
from django.db import models
# Create your models here.
class UserBaseInfo(models.Model):
id = models.AutoField(verbose_name='用户id', primary_key=True)
username = models.CharField(verbose_name='用户名', max_length=30)
password = models.CharField(verbose_name='密码', max_length=20)
age = models.IntegerField(verbose_name='年龄')
mobile = models.CharField(verbose_name='手机号', max_length=20)
status = models.CharField(verbose_name='状态', max_length=1)
create_date = models.DateField(verbose_name='创建时间', auto_now_add=True)
class UserStatus(models.Model):
id = models.AutoField(verbose_name='状态id', primary_key=True)
status = models.CharField(verbose_name='状态', max_length=10)

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

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.
Loading…
Cancel
Save