From 959232fa4a8fd327a23afec5b733b82116902609 Mon Sep 17 00:00:00 2001 From: amirhossein Date: Sat, 10 Oct 2020 23:20:20 +0330 Subject: [PATCH] added some advanced futures in admin panel such as search field display filter and list display just for communicating in this nice project --- bestoon/settings.py.sample | 128 ------------------------------------- web/admin.py | 29 +++++++-- web/models.py | 7 +- 3 files changed, 30 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/admin.py b/web/admin.py index 0a3f27e..ab58467 100644 --- a/web/admin.py +++ b/web/admin.py @@ -1,8 +1,29 @@ from django.contrib import admin from .models import Expense, Income, Token, News # Register your models here. +class NewsAdmin(admin.ModelAdmin): + list_display = ('title', 'date',) + list_filter = ('date',) + search_fields = ('title', 'text',) + class Meta: + model = News +class TokenAdmin(admin.ModelAdmin): + search_fields = ('user',) + class Meta: + model = Token +class IncomeAdmin(admin.ModelAdmin): + list_display = ('user', 'amount',) + list_filter = ('date',) + search_fields = ('title', 'text','amount',) + class Meta: + model = Income +class ExpenseAdmin(admin.ModelAdmin): + list_filter = ('date',) + search_fields = ('text', 'user','amount',) + class Meta: + model = Expense -admin.site.register(Expense) -admin.site.register(Income) -admin.site.register(Token) -admin.site.register(News) +admin.site.register(Expense,ExpenseAdmin) +admin.site.register(Income, IncomeAdmin) +admin.site.register(Token, TokenAdmin) +admin.site.register(News, NewsAdmin) diff --git a/web/models.py b/web/models.py index 14ed45c..581a891 100644 --- a/web/models.py +++ b/web/models.py @@ -9,6 +9,9 @@ class News(models.Model): title = models.CharField(max_length=250) text = models.TextField() date = models.DateTimeField() + class Meta: + verbose_name='News' + verbose_name_plural='News' def __unicode__(self): return self.title @@ -32,7 +35,7 @@ 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): return "{}-{}-{}".format(self.date, self.user, self.amount) @@ -42,7 +45,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): return "{}-{}-{}".format(self.date, self.user, self.amount)