Skip to content

Commit

Permalink
initial build with show and add expenses feature
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravgunjal71 committed Apr 8, 2020
0 parents commit 30b7ad1
Show file tree
Hide file tree
Showing 28 changed files with 490 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
Empty file added expensetrack/__init__.py
Empty file.
Binary file added expensetrack/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added expensetrack/__pycache__/admin.cpython-35.pyc
Binary file not shown.
Binary file added expensetrack/__pycache__/models.cpython-35.pyc
Binary file not shown.
Binary file added expensetrack/__pycache__/urls.cpython-35.pyc
Binary file not shown.
Binary file added expensetrack/__pycache__/views.cpython-35.pyc
Binary file not shown.
5 changes: 5 additions & 0 deletions expensetrack/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Expense

# Register your models here.
admin.site.register(Expense)
5 changes: 5 additions & 0 deletions expensetrack/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ExpensetrackConfig(AppConfig):
name = 'expensetrack'
7 changes: 7 additions & 0 deletions expensetrack/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.forms import ModelForm
from .models import Expense

class ExpenseForm(ModelForm):
class Meta:
model = Expense
fields = '__all__'
24 changes: 24 additions & 0 deletions expensetrack/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.2.12 on 2020-04-06 15:01

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Expense',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('item', models.CharField(max_length=50)),
('amount', models.IntegerField()),
('category', models.CharField(max_length=50)),
('date', models.DateField()),
],
),
]
Empty file.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions expensetrack/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.db import models

# Create your models here.
class Expense(models.Model):
item = models.CharField(max_length = 50)
amount = models.IntegerField()
category = models.CharField(max_length=50)
date = models.DateField()

def __str__(self):
return self.name
3 changes: 3 additions & 0 deletions expensetrack/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
7 changes: 7 additions & 0 deletions expensetrack/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path
from . import views

urlpatterns = [
path('', views.home, name = 'index'),
path('add', views.add, name = 'add')
]
25 changes: 25 additions & 0 deletions expensetrack/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.shortcuts import render, redirect
from .models import Expense
from django.http import HttpResponse


# Create your views here.
# home
def home(request):
expenses = Expense.objects.all()
return render(request, 'index.html', {'expenses': expenses})

# create
def add(request):
if request.method == 'POST':
item = request.POST['item']
amount = request.POST['amount']
category = request.POST['category']
date = request.POST['date']

expense = Expense(item=item, amount=amount, category=category, date=date)
expense.save()

return redirect(home)


Empty file added expensetracker/__init__.py
Empty file.
Binary file added expensetracker/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file not shown.
Binary file added expensetracker/__pycache__/urls.cpython-35.pyc
Binary file not shown.
Binary file added expensetracker/__pycache__/wsgi.cpython-35.pyc
Binary file not shown.
130 changes: 130 additions & 0 deletions expensetracker/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
"""
Django settings for expensetracker project.
Generated by 'django-admin startproject' using Django 2.2.12.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/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.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '5n!+x4y&9vzs)ejderz)-nmcn6vez_n3b5kmkc09lkww&ij0*%'

# 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',
'expensetrack'
]

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 = 'expensetracker.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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 = 'expensetracker.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'expensetracker',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
}
}
}


# Password validation
# https://docs.djangoproject.com/en/2.2/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.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

DATE_INPUT_FORMATS = ['%d/%m/%Y']

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
22 changes: 22 additions & 0 deletions expensetracker/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""expensetracker URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('expensetrack.urls'))
]
16 changes: 16 additions & 0 deletions expensetracker/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for expensetracker project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'expensetracker.settings')

application = get_wsgi_application()
21 changes: 21 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'expensetracker.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Loading

0 comments on commit 30b7ad1

Please sign in to comment.