Skip to content

Commit 45de74a

Browse files
committed
Lecture 11 added
1 parent 5bf95f2 commit 45de74a

32 files changed

+551
-9
lines changed

Lecture_10/zomato/db.sqlite3

0 Bytes
Binary file not shown.

Lecture_10/zomato/main/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ class Restaurant(models.Model):
1010
open_time = models.TimeField()
1111
close_time = models.TimeField()
1212

13+
def get_fields(self):
14+
fields = [ field for field in self._meta.get_fields() if field.name not in [ "id", "review" ]]
15+
16+
for f in fields:
17+
yield f.name, getattr(self, f.name)
18+
19+
1320
def get_rating(self):
1421
return self.review_set.aggregate(Avg('rating'))['rating__avg']
1522

Lecture_10/zomato/main/views.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from . import forms
77

88
# Create your views here.
9+
910
def index(request):
1011
context = {}
1112
return render(request, 'main/index.html', context)
@@ -15,8 +16,6 @@ def restaurants(request):
1516

1617
query_set = query_set.annotate(average_rating = Avg('review__rating')).order_by('-average_rating')
1718

18-
print(request.GET)
19-
2019
context = {
2120
"query_set": query_set,
2221
}
@@ -33,12 +32,19 @@ def add_restraunt(request):
3332
return HttpResponse("Form Added with id " + str(obj.pk))
3433

3534
context = {
36-
'form': form
35+
'rest_form': form
3736
}
3837
return render(request, 'main/addRestaurant.html', context)
3938

4039
def restaurant(request, id):
4140
rest = get_object_or_404(models.Restaurant, pk = id)
41+
42+
# try:
43+
# rest = models.Restaurant.objects.get(pk = id)
44+
# except:
45+
# raise Http404()
46+
47+
4248
success = False
4349

4450
# Handling the form
@@ -50,6 +56,7 @@ def restaurant(request, id):
5056
obj = form.save(commit = False)
5157
obj.restaurant = rest
5258
obj.save()
59+
5360
success = True
5461
form = forms.ReviewForm()
5562

Lecture_10/zomato/templates/main/addRestaurant.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
{% csrf_token %}
88

9-
{{ form.as_p }}
9+
{{ rest_form.as_p }}
1010

1111
<button type="submit">Submit</button>
1212

Lecture_10/zomato/templates/main/restaurant.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
{% block body %}
44

5-
Name: {{ restaurant.name }}<br>
6-
Address: {{ restaurant.address }}<br>
7-
Open Time: {{ restaurant.open_time }}<br>
8-
Close Time: {{ restaurant.close_time }}<br>
5+
{% for field_name, field_value in restaurant.get_fields %}
6+
7+
{{ field_name }}: {{ field_value }}<br>
8+
9+
{% endfor %}
910

1011
Average Rating: {{ restaurant.get_rating }}
1112

@@ -31,7 +32,11 @@ <h2> Add Review </h2>
3132

3233
{% csrf_token %}
3334

34-
{{ form.as_p }}
35+
<table>
36+
37+
{{ form.as_table }}
38+
39+
</table>
3540

3641
<button type="submit">Submit</button>
3742

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"python.pythonPath": "${workspaceFolder}/env/bin/python",
3+
"python.linting.pylintEnabled": false
4+
}
160 KB
Binary file not shown.

Lecture_11/library_system/library_system/__init__.py

Whitespace-only changes.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import os
2+
3+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
4+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
5+
6+
7+
# Quick-start development settings - unsuitable for production
8+
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
9+
10+
# SECURITY WARNING: keep the secret key used in production secret!
11+
SECRET_KEY = '&5o)47wsa%if6q52e5%doww9x6f-cg$_d(^voq_rby8@3o8f1o'
12+
13+
# SECURITY WARNING: don't run with debug turned on in production!
14+
DEBUG = True
15+
16+
ALLOWED_HOSTS = []
17+
18+
19+
# Application definition
20+
21+
INSTALLED_APPS = [
22+
'main',
23+
'django.contrib.admin',
24+
'django.contrib.auth',
25+
'django.contrib.contenttypes',
26+
'django.contrib.sessions',
27+
'django.contrib.messages',
28+
'django.contrib.staticfiles',
29+
]
30+
31+
MIDDLEWARE = [
32+
'django.middleware.security.SecurityMiddleware',
33+
'django.contrib.sessions.middleware.SessionMiddleware',
34+
'django.middleware.common.CommonMiddleware',
35+
'django.middleware.csrf.CsrfViewMiddleware',
36+
'django.contrib.auth.middleware.AuthenticationMiddleware',
37+
'django.contrib.messages.middleware.MessageMiddleware',
38+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
39+
]
40+
41+
ROOT_URLCONF = 'library_system.urls'
42+
43+
TEMPLATES = [
44+
{
45+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
46+
'DIRS': [os.path.join(BASE_DIR, 'templates/')],
47+
'APP_DIRS': True,
48+
'OPTIONS': {
49+
'context_processors': [
50+
'django.template.context_processors.debug',
51+
'django.template.context_processors.request',
52+
'django.contrib.auth.context_processors.auth',
53+
'django.contrib.messages.context_processors.messages',
54+
],
55+
},
56+
},
57+
]
58+
59+
WSGI_APPLICATION = 'library_system.wsgi.application'
60+
61+
62+
# Database
63+
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
64+
65+
DATABASES = {
66+
'default': {
67+
'ENGINE': 'django.db.backends.sqlite3',
68+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
69+
}
70+
}
71+
72+
73+
# Password validation
74+
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
75+
76+
AUTH_PASSWORD_VALIDATORS = [
77+
{
78+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
79+
},
80+
{
81+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
82+
},
83+
{
84+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
85+
},
86+
{
87+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
88+
},
89+
]
90+
91+
92+
# Internationalization
93+
# https://docs.djangoproject.com/en/2.0/topics/i18n/
94+
95+
LANGUAGE_CODE = 'en-us'
96+
97+
TIME_ZONE = 'UTC'
98+
99+
USE_I18N = True
100+
101+
USE_L10N = True
102+
103+
USE_TZ = True
104+
105+
106+
# Static files (CSS, JavaScript, Images)
107+
# https://docs.djangoproject.com/en/2.0/howto/static-files/
108+
109+
STATIC_URL = '/static/'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.contrib import admin
2+
from django.urls import path, include
3+
4+
urlpatterns = [
5+
path('', include('main.urls')),
6+
path('admin/', admin.site.urls),
7+
]

0 commit comments

Comments
 (0)