diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\215\201\345\233\233\345\221\250_\344\275\234\344\270\232/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\270\211\350\212\202\350\257\276_\344\275\234\344\270\232/model_test.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\215\201\345\233\233\345\221\250_\344\275\234\344\270\232/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\270\211\350\212\202\350\257\276_\344\275\234\344\270\232/model_test.py" new file mode 100644 index 0000000000000000000000000000000000000000..235c6059e98d46a3995135902ad99d8e8f347379 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\215\201\345\233\233\345\221\250_\344\275\234\344\270\232/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\270\211\350\212\202\350\257\276_\344\275\234\344\270\232/model_test.py" @@ -0,0 +1,36 @@ +import os +import random +import django + +def create_reader(): + for i in range(100): + reader = Reader( + name=f'name_{i}', + email=f'email_{i}@163.com', + null_test=None, + blank_test='', + whether_vip=random.choice([True, False]) + + ) + + #调用save会往数据插入一条数据或者更新一条数据 + reader.clean_fields(exclude=['null_test']) + reader.save(using="person") + +def retrieve_reader(): + reader_array = Reader.objects.using('person').all().filter(id__gt=300).order_by("name", "id") + reader_array = Reader.objects.exclude(email__icontains='@') + # reader_array = Reader.objects.filter(name__startswith='name_9') + # reader_array = Reader.objects.filter(name__startswith='name_9') + # reader_array = Reader.objects.filter(id__gte=300) + # reader_array = Reader.objects.get(pk=201) + # reader_array = Reader.objects.filter(name="name_0") + print(reader_array) + +if __name__ == "__main__": + #设置环境变量 + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") + django.setup() + from myblog.models import Reader + create_reader() + # retrieve_reader() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\215\201\345\233\233\345\221\250_\344\275\234\344\270\232/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\270\211\350\212\202\350\257\276_\344\275\234\344\270\232/models.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\215\201\345\233\233\345\221\250_\344\275\234\344\270\232/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\270\211\350\212\202\350\257\276_\344\275\234\344\270\232/models.py" new file mode 100644 index 0000000000000000000000000000000000000000..76e120a39eb849d4e2515d466e973f257bdd37ff --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\215\201\345\233\233\345\221\250_\344\275\234\344\270\232/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\270\211\350\212\202\350\257\276_\344\275\234\344\270\232/models.py" @@ -0,0 +1,28 @@ +from django.db import models + +# Create your models here. +class Person(models.Model): + name = models.CharField(max_length=191) + email = models.EmailField() + update_time = models.DateTimeField(auto_now=True) + create_time = models.DateTimeField(auto_now_add=True) + + null_test = models.CharField(max_length=200, null=True) + blank_test = models.CharField(max_length=200, blank=True) + + class Meta: + abstract = True + +class Reader(Person): + whether_vip = models.BooleanField(default=False) + + + class Meta: + db_table = "reader" + managed = False + get_latest_by = ["id"] + + +class Writer(Person): + pass + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\215\201\345\233\233\345\221\250_\344\275\234\344\270\232/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\270\211\350\212\202\350\257\276_\344\275\234\344\270\232/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\215\201\345\233\233\345\221\250_\344\275\234\344\270\232/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\270\211\350\212\202\350\257\276_\344\275\234\344\270\232/settings.py" new file mode 100644 index 0000000000000000000000000000000000000000..77806e049b43380b34e7cf5ae312ef1414ca7791 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\215\201\345\233\233\345\221\250_\344\275\234\344\270\232/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\270\211\350\212\202\350\257\276_\344\275\234\344\270\232/settings.py" @@ -0,0 +1,135 @@ +""" +Django settings for mysite project. + +Generated by 'django-admin startproject' using Django 2.0. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '-j*f=q)igfyn5cny*j(n3^1ap9*^7qy)x^r!@r@&j384%*5dls' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'libary.apps.LibaryConfig', + 'polls.apps.PollsConfig', + 'myblog.apps.MyblogConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'mysite.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'mysite.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'polls', + 'USER': 'root', + 'PASSWORD': 'zhang1128', + 'HOST': '127.0.0.1', + 'PORT': '3306' + }, + 'person': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'person', + 'USER': 'root', + 'PASSWORD': 'zhang1128', + 'HOST': '127.0.0.1', + 'PORT': '3306' + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\215\201\345\233\233\345\221\250_\344\275\234\344\270\232/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\270\211\350\212\202\350\257\276_\344\275\234\344\270\232/\347\273\203\344\271\240\346\225\260\346\215\256\345\272\223.png" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\215\201\345\233\233\345\221\250_\344\275\234\344\270\232/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\270\211\350\212\202\350\257\276_\344\275\234\344\270\232/\347\273\203\344\271\240\346\225\260\346\215\256\345\272\223.png" new file mode 100644 index 0000000000000000000000000000000000000000..d357e8cdf40af31b1c116e3fcbff45b4a4fa4929 Binary files /dev/null and "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\345\230\230\345\230\230/1\347\217\255_\345\230\230\345\230\230_\347\254\254\345\215\201\345\233\233\345\221\250_\344\275\234\344\270\232/1\347\217\255_\345\230\230\345\230\230_\347\254\254\344\270\211\350\212\202\350\257\276_\344\275\234\344\270\232/\347\273\203\344\271\240\346\225\260\346\215\256\345\272\223.png" differ