diff --git a/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc b/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc index dcd951f..8cc1645 100644 Binary files a/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc and b/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc differ diff --git a/SocialHelper/SocialHelper/__pycache__/urls.cpython-37.pyc b/SocialHelper/SocialHelper/__pycache__/urls.cpython-37.pyc index 7d29b82..b19e165 100644 Binary files a/SocialHelper/SocialHelper/__pycache__/urls.cpython-37.pyc and b/SocialHelper/SocialHelper/__pycache__/urls.cpython-37.pyc differ diff --git a/SocialHelper/SocialHelper/settings.py b/SocialHelper/SocialHelper/settings.py index fafb346..70f48eb 100644 --- a/SocialHelper/SocialHelper/settings.py +++ b/SocialHelper/SocialHelper/settings.py @@ -84,8 +84,6 @@ DATABASES = { } } - - # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators @@ -122,12 +120,11 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.1/howto/static-files/ +MEDIA_URL = '/media/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') + STATIC_ROOT = os.path.join(BASE_DIR,'static') STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR,'SocialHelper/static') ] - -# Media Folder Settings -MEDIA_ROOT = os.path.join(BASE_DIR, 'media' ) -MEDIA_URL = '/media/' diff --git a/SocialHelper/SocialHelper/urls.py b/SocialHelper/SocialHelper/urls.py index 5f16db5..37e56e3 100644 --- a/SocialHelper/SocialHelper/urls.py +++ b/SocialHelper/SocialHelper/urls.py @@ -1,22 +1,10 @@ -"""SocialHelper URL Configuration - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/2.1/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 include, path +from django.conf import settings +from django.conf.urls.static import static + urlpatterns = [ path('homepage/', include('homepage.urls')), path('admin/', admin.site.urls), -] +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/SocialHelper/homepage/__pycache__/forms.cpython-37.pyc b/SocialHelper/homepage/__pycache__/forms.cpython-37.pyc new file mode 100644 index 0000000..daf3ba0 Binary files /dev/null and b/SocialHelper/homepage/__pycache__/forms.cpython-37.pyc differ diff --git a/SocialHelper/homepage/__pycache__/models.cpython-37.pyc b/SocialHelper/homepage/__pycache__/models.cpython-37.pyc index c6a53e5..43a919c 100644 Binary files a/SocialHelper/homepage/__pycache__/models.cpython-37.pyc and b/SocialHelper/homepage/__pycache__/models.cpython-37.pyc differ diff --git a/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc b/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc index aac9133..a6d2c82 100644 Binary files a/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc and b/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc differ diff --git a/SocialHelper/homepage/__pycache__/views.cpython-37.pyc b/SocialHelper/homepage/__pycache__/views.cpython-37.pyc index 2558a53..a1bf143 100644 Binary files a/SocialHelper/homepage/__pycache__/views.cpython-37.pyc and b/SocialHelper/homepage/__pycache__/views.cpython-37.pyc differ diff --git a/SocialHelper/homepage/forms.py b/SocialHelper/homepage/forms.py new file mode 100644 index 0000000..ef89986 --- /dev/null +++ b/SocialHelper/homepage/forms.py @@ -0,0 +1,7 @@ +from django import forms + +class DocumentForm(forms.Form): + docfile = forms.FileField( + label='Select a file', + help_text='max. 42 megabytes' + ) diff --git a/SocialHelper/homepage/migrations/0002_product_picture.py b/SocialHelper/homepage/migrations/0002_product_picture.py new file mode 100644 index 0000000..5ce4fb0 --- /dev/null +++ b/SocialHelper/homepage/migrations/0002_product_picture.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.5 on 2020-12-10 18:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='product', + name='picture', + field=models.FileField(blank=True, null=True, upload_to='documents/%Y/%m/%d'), + ), + ] diff --git a/SocialHelper/homepage/migrations/0003_auto_20201210_2008.py b/SocialHelper/homepage/migrations/0003_auto_20201210_2008.py new file mode 100644 index 0000000..3ffff9f --- /dev/null +++ b/SocialHelper/homepage/migrations/0003_auto_20201210_2008.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.5 on 2020-12-10 19:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0002_product_picture'), + ] + + operations = [ + migrations.AlterField( + model_name='product', + name='picture', + field=models.ImageField(blank=True, null=True, upload_to='images/'), + ), + ] diff --git a/SocialHelper/homepage/migrations/__pycache__/0002_product_picture.cpython-37.pyc b/SocialHelper/homepage/migrations/__pycache__/0002_product_picture.cpython-37.pyc new file mode 100644 index 0000000..c9ac885 Binary files /dev/null and b/SocialHelper/homepage/migrations/__pycache__/0002_product_picture.cpython-37.pyc differ diff --git a/SocialHelper/homepage/migrations/__pycache__/0003_auto_20201210_2008.cpython-37.pyc b/SocialHelper/homepage/migrations/__pycache__/0003_auto_20201210_2008.cpython-37.pyc new file mode 100644 index 0000000..fb7dcb8 Binary files /dev/null and b/SocialHelper/homepage/migrations/__pycache__/0003_auto_20201210_2008.cpython-37.pyc differ diff --git a/SocialHelper/homepage/models.py b/SocialHelper/homepage/models.py index 5fc349e..f3a9e9c 100644 --- a/SocialHelper/homepage/models.py +++ b/SocialHelper/homepage/models.py @@ -7,6 +7,7 @@ TYPE_T = ( ) class Product(models.Model): + picture = models.ImageField(null=True, blank=True, upload_to="images/") create_date = models.DateField(("Date"), default=datetime.date.today) user_owner = models.TextField(max_length=40, blank=False, default="") type = models.IntegerField(choices = TYPE_T, blank=False, default="") diff --git a/SocialHelper/homepage/templates/homepage/Dodawanie.html b/SocialHelper/homepage/templates/homepage/Dodawanie.html index 5eafb6e..ef6180a 100644 --- a/SocialHelper/homepage/templates/homepage/Dodawanie.html +++ b/SocialHelper/homepage/templates/homepage/Dodawanie.html @@ -16,38 +16,51 @@ -
-
-
-
-
- - -
-
- - -
-
- - -
-
-
- Wybierz zdjęcie - -
-
-
- -
-
-
-
-
+
+ {% csrf_token %} + {{ form.media }} + {{ form.as_p }} +
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+ Wybierz zdjęcie + +
+
+
+ +
+ +
+
+
+ diff --git a/SocialHelper/homepage/templates/homepage/Mojeogloszenia.html b/SocialHelper/homepage/templates/homepage/Mojeogloszenia.html index 2e98fa4..381af48 100644 --- a/SocialHelper/homepage/templates/homepage/Mojeogloszenia.html +++ b/SocialHelper/homepage/templates/homepage/Mojeogloszenia.html @@ -30,7 +30,7 @@
- +
diff --git a/SocialHelper/homepage/urls.py b/SocialHelper/homepage/urls.py index 903f398..8d0ddc5 100644 --- a/SocialHelper/homepage/urls.py +++ b/SocialHelper/homepage/urls.py @@ -1,9 +1,13 @@ -from django.urls import path +from django.urls import path, include from . import views +from django.conf import settings +from django.conf.urls.static import static + urlpatterns = [ path('', views.index, name='index'), path('filter', views.filter, name='filter'), path('Dodawanie', views.Dodawanie, name='Dodawanie'), - path('Mojeogloszenia', views.Mojeogloszenia, name='Mojeogloszenia'), -] + path('Mojeogloszenia', views.Mojeogloszenia, name='Mojeogloszenia'), + +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/SocialHelper/homepage/views.py b/SocialHelper/homepage/views.py index 3f1de00..29f189d 100644 --- a/SocialHelper/homepage/views.py +++ b/SocialHelper/homepage/views.py @@ -2,8 +2,14 @@ from django.shortcuts import get_object_or_404, render from django.http import HttpResponse, HttpResponseRedirect from django.urls import reverse from django.template import loader + from .models import Product, TYPE_T +from django.utils import timezone +from datetime import timedelta +import datetime + + def index(request): all_product = Product.objects.all template = loader.get_template('homepage/index.html') @@ -53,10 +59,43 @@ def filter(request): return HttpResponse(template.render(context, request)) def Dodawanie(request): + if request.method == 'POST': + place_local = request.POST['place'] + type_local = request.POST['type'] + script_local = request.POST['script'] + title_local = request.POST['title'] + data_local = timezone.now() + pic_local = request.FILES['file'] + + product = Product( + picture = pic_local, + create_date = data_local, + user_owner = "jedrzejklepacki@wp.pl", + type = int(type_local), + title = title_local, + description = script_local, + place = place_local, + keywords = "", + ) + product.save() + all_product = Product.objects.filter(user_owner = "jedrzejklepacki@wp.pl") + template = loader.get_template('homepage/Mojeogloszenia.html') + types = TYPE_T + place_local = "" + oddam_local = "" + potrzebuje_local = "" + context = { + 'all_product': all_product, + 'types': types, + 'place_local': place_local, + 'oddam_local': oddam_local, + 'potrzebuje_local': potrzebuje_local, + } + return HttpResponse(template.render(context, request)) return render(request , 'homepage/Dodawanie.html') def Mojeogloszenia(request): - all_product = Product.objects.all + all_product = Product.objects.filter(user_owner = "jedrzejklepacki@wp.pl") template = loader.get_template('homepage/Mojeogloszenia.html') types = TYPE_T place_local = ""