From 2075bbde3bbdcef6bcb57a778503673f7bfc8b77 Mon Sep 17 00:00:00 2001 From: AlexJohnson2 Date: Mon, 18 Jan 2021 22:51:27 +0330 Subject: [PATCH] add on_delete variable to ForeignKey function and change unicode function to str in web/models.py --- bestoon/settings.py.sample | 128 ------------------------------------- web/models.py | 12 ++-- 2 files changed, 6 insertions(+), 134 deletions(-) delete mode 100644 bestoon/settings.py.sample diff --git a/bestoon/settings.py.sample b/bestoon/settings.py.sample deleted file mode 100644 index 84197fe..0000000 --- a/bestoon/settings.py.sample +++ /dev/null @@ -1,128 +0,0 @@ -""" -Django settings for bestoon project. - -Generated by 'django-admin startproject' using Django 1.10.4. - -For more information on this file, see -https://docs.djangoproject.com/en/1.10/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.10/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/1.10/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'GENERATE A RANDOM SECRET KEY AND REPLACE IT WITH THIS' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] - - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'corsheaders', - 'web', -] - -MIDDLEWARE = [ - 'corsheaders.middleware.CorsMiddleware', - '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 = 'bestoon.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 = 'bestoon.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/1.10/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - - -# Password validation -# https://docs.djangoproject.com/en/1.10/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/1.10/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/1.10/howto/static-files/ - -STATIC_URL = '/static/' - - - -RECAPTCHA_SECRET_KEY = '' -POSTMARK_API_TOKEN='' diff --git a/web/models.py b/web/models.py index 14ed45c..c96d424 100644 --- a/web/models.py +++ b/web/models.py @@ -9,7 +9,7 @@ class News(models.Model): title = models.CharField(max_length=250) text = models.TextField() date = models.DateTimeField() - def __unicode__(self): + def __str__(self): return self.title class Passwordresetcodes(models.Model): @@ -24,7 +24,7 @@ class Token(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) token = models.CharField(max_length=48) - def __unicode__(self): + def __str__(self): return "{}_token".format(self.user) @@ -32,9 +32,9 @@ class Expense(models.Model): text = models.CharField(max_length=255) date = models.DateTimeField() amount = models.BigIntegerField() - user = models.ForeignKey(User) + user = models.ForeignKey(User,on_delete=models.CASCADE) - def __unicode__(self): + def __str__(self): return "{}-{}-{}".format(self.date, self.user, self.amount) @@ -42,7 +42,7 @@ class Income(models.Model): text = models.CharField(max_length=255) date = models.DateTimeField() amount = models.BigIntegerField() - user = models.ForeignKey(User) + user = models.ForeignKey(User,on_delete=models.CASCADE) - def __unicode__(self): + def __str__(self): return "{}-{}-{}".format(self.date, self.user, self.amount)