-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add view, template and making management command for data
- Loading branch information
onurtacc
committed
Jul 6, 2019
1 parent
5f57f17
commit 7583104
Showing
9 changed files
with
41,686 additions
and
77 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from django.core.management.base import BaseCommand | ||
from inventory_tracking.core.models import Building, Apartment, Room, Furniture | ||
import random | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Insert 20 Building, 10 Apartment, 3 Room, 5 Furniture into database." | ||
|
||
def handle(self, *args, **options): | ||
self.stdout.write("Cleaning Database...") | ||
Building.objects.all().delete() | ||
|
||
self.stdout.write("Generating Buildings...") | ||
buildings = [] | ||
|
||
for num in range(1, 21): | ||
buildings.append( | ||
Building(name=f"Apartman #{num}", no=random.randint(1, 40), address=f"Lorem Ipsum Dolor Sit Amet") | ||
) | ||
|
||
Building.objects.bulk_create(buildings) | ||
|
||
self.stdout.write("Generating Apartments...") | ||
apartments = [] | ||
apartment_id = 1 | ||
|
||
for build in Building.objects.all(): | ||
apartment_no = 1 | ||
for num in range(apartment_id * 10, (apartment_id * 10 + 10)): | ||
apartments.append( | ||
Apartment( | ||
building=build, | ||
apartment_no=apartment_no, | ||
floor=random.randint(1, 10), | ||
square_meter=random.randint(60, 160) | ||
) | ||
) | ||
apartment_no += 1 | ||
apartment_id += 1 | ||
|
||
Apartment.objects.bulk_create(apartments) | ||
|
||
self.stdout.write("Generating Rooms...") | ||
|
||
rooms = [] | ||
room_names = ['Mutfak', 'Oturma Odası', 'Salon'] | ||
for apart in Apartment.objects.all(): | ||
for name in room_names: | ||
rooms.append( | ||
Room( | ||
apartment=apart, | ||
name=name | ||
) | ||
) | ||
|
||
Room.objects.bulk_create(rooms) | ||
|
||
self.stdout.write("Generating Furnishings...") | ||
|
||
furniture = [] | ||
furnishings = ['Televizyon', 'Bilgisayar', 'Kanepe', 'Halı', 'Masa'] | ||
|
||
for r in Room.objects.all(): | ||
for furnt in furnishings: | ||
furniture.append( | ||
Furniture( | ||
room=r, | ||
name=furnt, | ||
price=random.randint(200, 4000) | ||
) | ||
) | ||
Furniture.objects.bulk_create(furniture) | ||
|
||
self.stdout.write( | ||
self.style.SUCCESS(f'Inserted 20 Building, 10 Apartment, 3 Room and 5 Furniture') | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
from django.shortcuts import render | ||
from .models import Building, Apartment, Room, Furniture | ||
|
||
# Create your views here. | ||
|
||
def listing(request): | ||
payload = { | ||
'buildings': Building.objects.all() | ||
} | ||
return render(request, "list.html", payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,8 @@ | ||
"""inventory_tracking 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 | ||
from .core import views | ||
|
||
urlpatterns = [ | ||
path('admin/', admin.site.urls), | ||
path('', views.listing, name='list'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!doctype html> | ||
<html lang="tr"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<h1>Buildings</h1> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>No</th> | ||
<th>Address</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for build in buildings %} | ||
<tr> | ||
<td>{{ build.name }}</td> | ||
<td>{{ build.no }}</td> | ||
<td>{{ build.address }}</td> | ||
<td> | ||
<a href="">details</a> | ||
<a href="">edit</a> | ||
<a href="">delete</a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</body> | ||
</html> |