Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # LightyNicole, a balloon flight company owned by one and only, comedian Vlatco Spasev!
- # managed to create both index and flights.html, as well as the unnecessary edit functionality for every listed flight, just to make sure I am on track with Djangosrce.
- #although, it might have made more sense if it showed details when you click on a flight rather than editing it.
- ----------------------------models.py------------------------------------
- from django.db import models
- from django.contrib.auth.models import User
- # Create your models here.
- class Pilot(models.Model):
- name = models.CharField(max_length=50)
- surname = models.CharField(max_length=50)
- year_of_birth = models.IntegerField()
- hours_in_air = models.IntegerField()
- role = models.CharField(max_length=50)
- class Balloon(models.Model):
- type = models.CharField(max_length=50)
- manifactor_name = models.CharField(max_length=50)
- max_attendees = models.IntegerField()
- class Aerocompany(models.Model):
- name = models.CharField(max_length=50)
- year = models.IntegerField()
- flyOutOfEU = models.BooleanField(default=False)
- class Flight(models.Model):
- code = models.CharField(max_length=50)
- airport_from = models.CharField(max_length=50)
- airport_to = models.CharField(max_length=50)
- user = models.ForeignKey(User, on_delete=models.CASCADE)
- image = models.ImageField(upload_to='sliki/', null=True, blank=True)
- balloon = models.ForeignKey(Balloon,models.CASCADE)
- aerocompany = models.ForeignKey(Aerocompany,models.CASCADE)
- class AerocompanyPilot(models.Model):
- aerocompany = models.ForeignKey(Aerocompany, models.CASCADE)
- pilot = models.ForeignKey(Pilot,models.CASCADE)
- ----------------------------admin.py------------------------------------
- from django.contrib import admin
- from .models import Aerocompany,Balloon,Flight,Pilot,AerocompanyPilot
- # Register your models here.
- class AerocompanyPilotInline(admin.TabularInline):
- model = AerocompanyPilot
- extra = 1
- class PilotAdmin(admin.ModelAdmin):
- list_display = ('name', 'surname',)
- class AerocompanyAdmin(admin.ModelAdmin):
- inlines = [AerocompanyPilotInline]
- list_display = ('name',)
- class FlightAdmin(admin.ModelAdmin):
- exclude = ("user",)
- def save_model(self, request, obj, form, change):
- obj.user = request.user
- super().save_model(request, obj, form, change)
- def has_change_permission(self, request, obj=None):
- if obj and obj.user==request.user:
- return True
- return False
- def has_delete_permission(self, request, obj=None):
- return False
- admin.site.register(Flight, FlightAdmin)
- admin.site.register(Aerocompany, AerocompanyAdmin)
- admin.site.register(Pilot, PilotAdmin)
- admin.site.register(Balloon)
- ----------------------------settings.py------------------------------------
- import os
- from pathlib import Path
- INSTALLED_APPS = [
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- 'BalloonApp'
- ]
- STATIC_URL = 'static/'
- MEDIA_ROOT = os.path.join(BASE_DIR,'media/')
- MEDIA_URL = '/media/'
- ----------------------------urls.py------------------------------------
- from django.contrib import admin
- from django.urls import path
- from django.conf.urls.static import static
- from django.conf import settings
- from BaloonApp.views import flights, index, edit_flight
- urlpatterns = [
- path('admin/', admin.site.urls),
- path('index/', index, name='index.html',),
- path('flights/', flights, name='flights.html'),
- # path('details/<int:pk>/',details, name='details.html' ),
- path('edit_flight/<int:pk>/', edit_flight, name='edit_flight.html'),
- # path('deleteProduct/<int:pk>/', deleteProduct, name='deleteProduct.html'),
- ] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
- ----------------------------views.py------------------------------------
- from django.shortcuts import render, redirect
- from .models import Flight
- from .forms import FlightForm
- from django.shortcuts import get_object_or_404
- # Create your views here.
- def flights(request):
- if request.method=="POST":
- form = FlightForm(request.POST, request.FILES)
- if form.is_valid():
- flight = form.save(commit=False)
- flight.user= request.user
- flight.image = form.cleaned_data['image']
- flight.save()
- return redirect("flights.html")
- queryset = Flight.objects.filter(airport_from="Skopje").all()
- context = {'flights': queryset, 'form': FlightForm}
- return render(request,'flights.html',context = context)
- def index(request):
- return render(request,'index.html')
- def edit_flight(request,pk):
- flight = get_object_or_404(Flight, pk=pk)
- if request.method=="POST":
- form = FlightForm(request.POST, request.FILES, instance=flight)
- if form.is_valid():
- form.save()
- return redirect("flights.html")
- form = FlightForm(instance=flight)
- return render(request, 'edit_flight.html', {'form': form})
- ----------------------------forms.py------------------------------------
- from django import forms
- from .models import Flight
- class FlightForm(forms.ModelForm):
- def __init__(self, *args, **kwargs):
- super(FlightForm, self).__init__(*args, **kwargs)
- for field in self.visible_fields():
- field.field.widget.attrs['class'] = "form-control"
- class Meta:
- model = Flight
- exclude = ['user', ]
- ----------------------------templates------------------------------------
- #import the bootstrap framework in each .html file's head tag:
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
- ----------------------------index.html------------------------------------
- <body>
- <div style="background-image: url('https://static.mycity.travel/manage/uploads/8/59/67650/1/vols-en-montgolfiere_1080.jpg'); background-blend-mode: darken">
- <ul class="nav justify-content-center ">
- <li class="nav-item" >
- <a style="color: white" class="nav-link active" style="justify-self: left" aria-current="page" href="#">Home</a>
- </li>
- <li class="nav-item dropdown">
- <a style="color: white" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Flights</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="{% url 'flights.html' %}">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- <li class="nav-item dropdown">
- <a style="color: white" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Planes</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- </li>
- <li class="nav-item dropdown">
- <a style="color: white" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">About Us</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- </li>
- <li class="nav-item dropdown">
- <a style="color: white" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Contact</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- </li>
- </ul>
- <p class="display-6" style="text-align: center; color: white; padding-top: 200px" >Best Airline Company</p>
- <hr style="width: 20px; color: white">
- <h1 class="display-1" style="text-align: center; color: white">Hot Air Balloon Rides</h1>
- <div style="text-align: center; margin-top: 20px; padding-bottom: 80px">
- <button class="btn btn-primary">Get Your Ticket</button></div>
- </div>
- <div class="container" style="padding-top: 10px; margin-top: 100px" >
- <div class="row" style="justify-content: center">
- <div class="col-md-6">
- <h4 class="display-6" style="text-align: center; margin: 10px"><b>Safety First</b></h4>
- <p style="margin-top: 20px; text-align: center">Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv.
- Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole
- Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole
- Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole
- Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole
- Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole </p>
- <div style="text-align: center; margin-top: 20px">
- <button class="btn btn-primary">Read More</button>
- </div>
- </div>
- <div class="col-md-6">
- <img src="https://mobirise.com/bootstrap-template/best-bootstrap-templates/assets/images/ian-dooley-407846-unsplash-1110x740.jpg" style="height: 350px"; width="500px">
- </div>
- </div>
- </div>
- <div class="container" style="padding-top: 10px; margin-top: 100px" >
- <div class="row" style="justify-content: center">
- <div class="col-md-6">
- <img src="https://mobirise.com/bootstrap-template/best-bootstrap-templates/assets/images/ravali-yan-96009-unsplash-1110x740.jpg" style="height: 350px"; width="500px">
- </div>
- <div class="col-md-6">
- <h4 class="display-6" style="text-align: center; margin: 10px"><b>More Fun</b></h4>
- <p style="margin-top: 20px; text-align: center">Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv.
- Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole
- Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole
- Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole
- Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole
- Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole Panoramic view of Sv. Nikole </p>
- <div style="text-align: center; margin-top: 20px">
- <button class="btn btn-primary">Read More</button>
- </div>
- </div>
- </div>
- </div>
- <h2 class="display-5" style="text-align: center; margin-top: 40px"><b>Tickets</b></h2>
- <div class="container" style="padding-top: 10px; margin-top: 40px">
- <div class="row" style="justify-content: center">
- <div class="col-md-4 card mb-4" >
- <div class="card" >
- <div style="text-align: center; background-color: deepskyblue; color: white" >
- <h4 style="padding-top: 20px">For Children(6-22 years old)</h4>
- <h6 class="display-6" style="padding-bottom: 20px">20$</h6>
- </div>
- <div class="card-body" style="text-align: center; background-color: lightgray; color: black">
- <p>Visit Sv. Nikole</p>
- <hr>
- <p>Everywhere beauty</p>
- <hr>
- <p>Games with no frontiers</p>
- <button><a class="btn btn">Book Now</a></button>
- </div>
- </div>
- </div>
- <div class="col-md-4 card mb-4" >
- <div class="card" >
- <div style="text-align: center; background-color: deepskyblue; color: white" >
- <h4 style="padding-top: 20px">For Children(6-22 years old)</h4>
- <h6 class="display-6" style="padding-bottom: 20px">20$</h6>
- </div>
- <div class="card-body" style="text-align: center; background-color: lightgray; color: black">
- <p>Visit Sv. Nikole</p>
- <hr>
- <p>Everywhere beauty</p>
- <hr>
- <p>Games with no frontiers</p>
- <button><a class="btn btn">Book Now</a></button>
- </div>
- </div>
- </div>
- <div class="col-md-4 card mb-4" >
- <div class="card" >
- <div style="text-align: center; background-color: deepskyblue; color: white" >
- <h4 style="padding-top: 20px">For Children(6-22 years old)</h4>
- <h6 class="display-6" style="padding-bottom: 20px">20$</h6>
- </div>
- <div class="card-body" style="text-align: center; background-color: lightgray; color: black">
- <p>Visit Sv. Nikole</p>
- <hr>
- <p>Everywhere beauty</p>
- <hr>
- <p>Games with no frontiers</p>
- <button><a class="btn btn">Book Now</a></button>
- </div>
- </div>
- </div>
- </div>
- </div>
- <footer class="bg-primary" data-bs-theme="dark" style="padding-top: 20px; padding-bottom: 20px; margin-top: 40px">
- <div class="container-fluid" style="text-align: center; color: white">
- <h6 href="#">Copyright 2022 FINKI DNIC All Rights Reserved</h6>
- </div>
- </footer>
- </body>
- ----------------------------flights.html------------------------------------
- <body>
- <div style="background-image: url('https://static.mycity.travel/manage/uploads/8/59/67650/1/vols-en-montgolfiere_1080.jpg'); background-blend-mode: darken">
- <ul class="nav justify-content-center ">
- <li class="nav-item" >
- <a style="color: white" class="nav-link active" style="justify-self: left" aria-current="page" href="{% url 'index.html' %}">Home</a>
- </li>
- <li class="nav-item dropdown">
- <a style="color: white" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Flights</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- <li class="nav-item dropdown">
- <a style="color: white" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Planes</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- </li>
- <li class="nav-item dropdown">
- <a style="color: white" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">About Us</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- </li>
- <li class="nav-item dropdown">
- <a style="color: white" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Contact</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- </li>
- </ul>
- <p class="display-6" style="text-align: center; color: white; padding-top: 200px" >Best Airline Company</p>
- <hr style="width: 20px; color: white">
- <h1 class="display-1" style="text-align: center; color: white">Hot Air Balloon Rides</h1>
- <div style="text-align: center; margin-top: 20px; padding-bottom: 80px">
- <button class="btn btn-primary">Get Your Ticket</button></div>
- </div>
- </div>
- <div class="container" style="padding-top: 40px;">
- <div class="row" style="justify-content: center">
- {% for flight in flights %}
- <div class="col-md-4 card mb-4" style="max-width: 18rem;">
- <div class="card" style="width: 18rem;" style="border-color: red">
- <img src= "{{ MEDIA_URL }} {{ flight.image.url }}" alt="...">
- <div class="card-body text-bg-dark">
- <h4 class="card-title"><b> {{flight.code}}</b></h4>
- <h5 class="card-title">{{flight.airport_from}} - {{flight.airport_to}}</h5>
- <p>Some quick example text to build on the card title and make up the bulk of the card's content.</p>
- <button><a href="{% url 'edit_flight.html' flight.pk %}" class="btn btn" >Book Now</a></button>
- </div>
- </div>
- </div>
- {% endfor %}
- </div>
- </div>
- <div class="container" style="padding: 20px; background-color: whitesmoke; box-shadow: black; margin-top: 40px">
- <form method="post" enctype="multipart/form-data">
- {% csrf_token %}
- {{ form.as_p }}
- <button class="btn btn-primary" type="submit">Submit</button>
- </form>
- </div>
- <footer class="bg-primary" data-bs-theme="dark" style="padding-top: 20px; padding-bottom: 20px; margin-top: 40px">
- <div class="container-fluid" style="text-align: center; color: white">
- <h6 href="#">Copyright 2022 FINKI DNIC All Rights Reserved</h6>
- </div>
- </footer>
- </body>
- ----------------------------edit_flight.py------------------------------------
- <body>
- <div style="background-image: url('https://static.mycity.travel/manage/uploads/8/59/67650/1/vols-en-montgolfiere_1080.jpg'); background-blend-mode: darken">
- <ul class="nav justify-content-center ">
- <li class="nav-item" >
- <a style="color: white" class="nav-link active" style="justify-self: left" aria-current="page" href="{% url 'index.html' %}">Home</a>
- </li>
- <li class="nav-item dropdown">
- <a style="color: white" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Flights</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- <li class="nav-item dropdown">
- <a style="color: white" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Planes</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- </li>
- <li class="nav-item dropdown">
- <a style="color: white" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">About Us</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- </li>
- <li class="nav-item dropdown">
- <a style="color: white" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Contact</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- </li>
- </ul>
- <p class="display-6" style="text-align: center; color: white; padding-top: 200px" >Best Airline Company</p>
- <hr style="width: 20px; color: white">
- <h1 class="display-1" style="text-align: center; color: white">Hot Air Balloon Rides</h1>
- <div style="text-align: center; margin-top: 20px; padding-bottom: 80px">
- <button class="btn btn-primary">Get Your Ticket</button></div>
- </div>
- </div>
- <h2 style="text-align: center; margin-top: 40px">Edit the Flight {{ flight.pk }}</h2>
- <div class="container" style="padding-top: 40px; background-color: whitesmoke; box-shadow: black;">
- <form method="post" enctype="multipart/form-data">
- {% csrf_token %}
- {{ form.as_p }}
- <button class="btn btn-primary" type="submit">Submit</button>
- </form>
- </div>
- <footer class="bg-primary" data-bs-theme="dark" style="padding-top: 20px; padding-bottom: 20px; margin-top: 40px">
- <div class="container-fluid" style="text-align: center; color: white">
- <h6 href="#">Copyright 2022 FINKI DNIC All Rights Reserved</h6>
- </div>
- </footer>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement