forked from wnata/green_lantern
-
Notifications
You must be signed in to change notification settings - Fork 0
HW Done #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Galyopa
wants to merge
1
commit into
Django_views_practice
Choose a base branch
from
Django_views_practice_HW
base: Django_views_practice
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
HW Done #13
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
46 changes: 46 additions & 0 deletions
46
lantern/django/django_orm/src/apps/cars/templates/cars_list.html
This file contains hidden or 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,46 @@ | ||
| {% extends "base.html" %} | ||
|
|
||
| {% block content %} | ||
| <table class="table table-bordered"> | ||
| <thead> | ||
| <tr> | ||
| <th>Model</th> | ||
| <th>Brand</th> | ||
| <th>Price</th> | ||
| <th>Dealer Name</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {% for car in cars %} | ||
| <tr> | ||
| <td>{{ car.model }}</td> | ||
| <td>{{ car.model.brand }}</td> | ||
| <td>{{ car.price }}</td> | ||
| <td>{{ car.dealer.first_name }}</td> | ||
| </tr> | ||
| {% endfor %} | ||
| </tbody> | ||
| </table> | ||
|
|
||
| {% if is_paginated %} | ||
| <ul class="pagination"> | ||
| {% if page_obj.has_previous %} | ||
| <li><a href="?page={{ page_obj.previous_page_number }}">«</a></li> | ||
| {% else %} | ||
| <li class="disabled"><span>«</span></li> | ||
| {% endif %} | ||
| {% for i in paginator.page_range %} | ||
| {% if page_obj.number == i %} | ||
| <li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li> | ||
| {% else %} | ||
| <li><a href="?page={{ i }}">{{ i }}</a></li> | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% if page_obj.has_next %} | ||
| <li><a href="?page={{ page_obj.next_page_number }}">»</a></li> | ||
| {% else %} | ||
| <li class="disabled"><span>»</span></li> | ||
| {% endif %} | ||
| </ul> | ||
| {% endif %} | ||
| {% endblock %} |
46 changes: 46 additions & 0 deletions
46
lantern/django/django_orm/src/apps/cars/templates/dealers.html
This file contains hidden or 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,46 @@ | ||
| {% extends "base.html" %} | ||
|
|
||
| {% block content %} | ||
| <table class="table table-bordered"> | ||
| <thead> | ||
| <tr> | ||
| <th>Dealer username</th> | ||
| <th>Dealer Full Name</th> | ||
| <th>Dealer's country</th> | ||
| <th>Dealer's city</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {% for dealer in dealers %} | ||
| <tr> | ||
| <td>{{ dealer.username }}</td> | ||
| <td>{{ dealer.full_name }}</td> | ||
| <td>{{ dealer.city.country }}</td> | ||
| <td>{{ dealer.city}}</td> | ||
| </tr> | ||
| {% endfor %} | ||
| </tbody> | ||
| </table> | ||
|
|
||
| {% if is_paginated %} | ||
| <ul class="pagination"> | ||
| {% if page_obj.has_previous %} | ||
| <li><a href="?page={{ page_obj.previous_page_number }}">«</a></li> | ||
| {% else %} | ||
| <li class="disabled"><span>«</span></li> | ||
| {% endif %} | ||
| {% for i in paginator.page_range %} | ||
| {% if page_obj.number == i %} | ||
| <li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li> | ||
| {% else %} | ||
| <li><a href="?page={{ i }}">{{ i }}</a></li> | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% if page_obj.has_next %} | ||
| <li><a href="?page={{ page_obj.next_page_number }}">»</a></li> | ||
| {% else %} | ||
| <li class="disabled"><span>»</span></li> | ||
| {% endif %} | ||
| </ul> | ||
| {% endif %} | ||
| {% endblock %} | ||
This file contains hidden or 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,13 @@ | ||
| from django.contrib.auth.decorators import login_required | ||
| from django.urls import path | ||
|
|
||
| from apps.cars.views import CarsListView, DealersCarListView | ||
| from apps.photos.views import PhotoView | ||
|
|
||
| app_name = 'cars' | ||
|
|
||
| urlpatterns = [ | ||
| path('cars_list/', CarsListView.as_view(), name='cars_list'), | ||
| path('cars_photo/', login_required(PhotoView.as_view()), name='cars_photo_url'), | ||
| path('dealers_list/', DealersCarListView.as_view(), name='dealers_list_url'), | ||
| ] |
This file contains hidden or 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,25 @@ | ||
| from django.shortcuts import render | ||
| from django.views.generic import ListView | ||
|
|
||
| # Create your views here. | ||
| from apps.cars.models import Car | ||
| from apps.dealers.models import Dealer | ||
|
|
||
|
|
||
| class CarsListView(ListView): | ||
| model = Car | ||
| template_name = 'cars_list.html' | ||
| context_object_name = 'cars' | ||
| paginate_by = 10 | ||
| queryset = Car.objects.all() | ||
|
|
||
|
|
||
| class DealersCarListView(ListView): | ||
| model = Dealer | ||
| template_name = 'dealers.html' | ||
| context_object_name = 'dealers' | ||
| paginate_by = 10 | ||
|
|
||
| def get_queryset(self): | ||
| if self.kwargs: | ||
| return Dealer.objects.all().filter(user_ptr_id=int(self.kwargs.get('pk'))) | ||
| else: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you do not need this else |
||
| return Dealer.objects.all() | ||
This file contains hidden or 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,18 @@ | ||
| from django.contrib import admin | ||
|
|
||
| # Register your models here. | ||
| from apps.dealers.models import Dealer, City, Country | ||
|
|
||
|
|
||
| @admin.register(Dealer) | ||
| class CarModelAdmin(admin.ModelAdmin): | ||
| list_display = ('username', 'title') | ||
|
|
||
|
|
||
| @admin.register(City) | ||
| class CarModelAdmin(admin.ModelAdmin): | ||
| list_display = ('name', 'country') | ||
|
|
||
|
|
||
| @admin.register(Country) | ||
| class CarModelAdmin(admin.ModelAdmin): | ||
| list_display = ('name', 'code') |
17 changes: 17 additions & 0 deletions
17
lantern/django/django_orm/src/apps/dealers/migrations/0003_auto_20200616_1837.py
This file contains hidden or 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,17 @@ | ||
| # Generated by Django 3.0.6 on 2020-06-16 18:37 | ||
|
|
||
| from django.db import migrations | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('dealers', '0002_delete_newsletter'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterModelOptions( | ||
| name='dealer', | ||
| options={'verbose_name': 'Dealer', 'verbose_name_plural': 'Dealers'}, | ||
| ), | ||
| ] |
This file contains hidden or 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,5 +1,6 @@ | ||
| from django.db import models | ||
| from django.contrib.auth.models import User | ||
| from django.utils.translation import gettext_lazy as _ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try to not use |
||
|
|
||
|
|
||
| class Country(models.Model): | ||
|
|
@@ -22,4 +23,13 @@ class Dealer(User): | |
| title = models.CharField(max_length=255) | ||
| city = models.ForeignKey(City, on_delete=models.DO_NOTHING) | ||
|
|
||
| @property | ||
| def full_name(self): | ||
| return f'{self.first_name} {self.last_name}' | ||
|
|
||
| def __str__(self): | ||
| return self.full_name | ||
|
|
||
| class Meta: | ||
| verbose_name = _('Dealer') | ||
| verbose_name_plural = _('Dealers') | ||
This file contains hidden or 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 @@ | ||
| from django.shortcuts import render | ||
|
|
||
| # Create your views here. | ||
| pass |
This file contains hidden or 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,12 @@ | ||
| from django.forms import ModelForm | ||
| from django import forms | ||
| from apps.photos.models import Photo | ||
|
|
||
|
|
||
| class PhotosForm(ModelForm): | ||
| class Meta: | ||
| model = Photo | ||
| fields = "__all__" | ||
| widgets = { | ||
| 'image': forms.ClearableFileInput(attrs={'multiple': True}), | ||
| } |
31 changes: 31 additions & 0 deletions
31
lantern/django/django_orm/src/apps/photos/migrations/0001_initial.py
This file contains hidden or 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,31 @@ | ||
| # Generated by Django 3.0.6 on 2020-06-18 16:02 | ||
|
|
||
| import django.core.validators | ||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| initial = True | ||
|
|
||
| dependencies = [ | ||
| ('cars', '0002_auto_20200605_1125'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='Photo', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('created_at', models.DateTimeField(auto_now_add=True)), | ||
| ('updated_at', models.DateTimeField(auto_now=True)), | ||
| ('image', models.ImageField(upload_to='photos/')), | ||
| ('position', models.SmallIntegerField(default=1, validators=[django.core.validators.MinValueValidator(limit_value=1)])), | ||
| ('car', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='photos', to='cars.Car')), | ||
| ], | ||
| options={ | ||
| 'ordering': ['position'], | ||
| }, | ||
| ), | ||
| ] |
Empty file.
This file contains hidden or 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,14 +1,13 @@ | ||
| from django.core.validators import MinValueValidator | ||
| from django.db import models | ||
|
|
||
| # Create your models here. | ||
| from common.models import BaseDateAuditModel | ||
|
|
||
|
|
||
| class Photo(BaseDateAuditModel): | ||
| image = models.ImageField(upload_to='photos/') | ||
| position = models.SmallIntegerField(default=1, validators=[MinValueValidator(limit_value=1)]) | ||
| car = models.ForeignKey('cars.Car', on_delete=models.CASCADE, related_name='photos') | ||
| car = models.ForeignKey(to='cars.Car', on_delete=models.CASCADE, related_name='photos') | ||
|
|
||
| class Meta: | ||
| ordering = ['position'] |
11 changes: 11 additions & 0 deletions
11
lantern/django/django_orm/src/apps/photos/templates/add_photo_to_car_form.html
This file contains hidden or 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,11 @@ | ||
| {% extends "base.html" %} | ||
|
|
||
| {% block content %} | ||
| {% if user.is_authenticated %} | ||
| <form method="post" action="{% url 'cars:cars_photo_url' %}"> | ||
| {% csrf_token %} | ||
| {{ form }} | ||
| <input type="submit" value="Save"> | ||
| </form> | ||
| {% endif %} | ||
| {% endblock %} |
This file contains hidden or 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,18 @@ | ||
| from django.shortcuts import render | ||
| from django.urls import reverse_lazy | ||
| from django.views.generic import FormView | ||
|
|
||
| # Create your views here. | ||
|
|
||
| from apps.photos.forms import PhotosForm | ||
|
|
||
|
|
||
| class PhotoView(FormView): | ||
| template_name = 'add_photo_to_car_form.html' | ||
| form_class = PhotosForm | ||
| success_url = reverse_lazy('success_page_url') | ||
|
|
||
| def get_object(self): | ||
| return self.request.user | ||
|
|
||
| def form_valid(self, form): | ||
| form.save() | ||
| return super().form_valid(form) |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
endline