dodawanie ogloszen backend
This commit is contained in:
parent
875ace9eaf
commit
8444d95979
Binary file not shown.
Binary file not shown.
@ -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/'
|
||||
|
@ -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)
|
||||
|
BIN
SocialHelper/homepage/__pycache__/forms.cpython-37.pyc
Normal file
BIN
SocialHelper/homepage/__pycache__/forms.cpython-37.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7
SocialHelper/homepage/forms.py
Normal file
7
SocialHelper/homepage/forms.py
Normal file
@ -0,0 +1,7 @@
|
||||
from django import forms
|
||||
|
||||
class DocumentForm(forms.Form):
|
||||
docfile = forms.FileField(
|
||||
label='Select a file',
|
||||
help_text='max. 42 megabytes'
|
||||
)
|
18
SocialHelper/homepage/migrations/0002_product_picture.py
Normal file
18
SocialHelper/homepage/migrations/0002_product_picture.py
Normal file
@ -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'),
|
||||
),
|
||||
]
|
18
SocialHelper/homepage/migrations/0003_auto_20201210_2008.py
Normal file
18
SocialHelper/homepage/migrations/0003_auto_20201210_2008.py
Normal file
@ -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/'),
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
@ -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="")
|
||||
|
@ -16,38 +16,51 @@
|
||||
<!--================End Categories Banner Area =================-->
|
||||
|
||||
<!--================Register Area =================-->
|
||||
<section class="track_area p_100">
|
||||
<div class="container">
|
||||
<div class="track_inner">
|
||||
<form class="track_form row">
|
||||
<div class="col-lg-12 form-group">
|
||||
<label for="cun">Typ ogłoszenia <span>*</span></label>
|
||||
<select id="cun">
|
||||
<option>Oddam</option>
|
||||
<option>Potrzebuję</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-12 form-group">
|
||||
<label for="name">Miejscowość <span>*</span></label>
|
||||
<input type="text" class="form-control" id="name" aria-describedby="name" placeholder="">
|
||||
</div>
|
||||
<div class="col-lg-12 form-group">
|
||||
<label for="order">Opis <span>*</span></label>
|
||||
<textarea class="form-control" id="order" rows="3"></textarea>
|
||||
</div>
|
||||
<div class="col-lg-12 form-group">
|
||||
<div class="file-field">
|
||||
<span>Wybierz zdjęcie</span>
|
||||
<input type="file">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-12 form-group">
|
||||
<button type="submit" value="submit" class="btn subs_btn form-control">Dodaj</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<form action="{% url 'Dodawanie' %}" method="POST" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{{ form.media }}
|
||||
{{ form.as_p }}
|
||||
<section class="track_area p_100">
|
||||
<div class="container">
|
||||
<div class="track_inner">
|
||||
<form class="track_form row">
|
||||
<div class="col-lg-12 form-group">
|
||||
<label for="cun">Typ ogłoszenia <span>*</span></label>
|
||||
<select id="cun" name="type">
|
||||
<option value="2">Oddam</option>
|
||||
<option value="1">Potrzebuję</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-12 form-group">
|
||||
<label for="name">Tytył <span>*</span></label>
|
||||
<input type="text" class="form-control" id="name" aria-describedby="name" placeholder="" name="title">
|
||||
</div>
|
||||
|
||||
<div class="col-lg-12 form-group">
|
||||
<label for="name">Miejscowość <span>*</span></label>
|
||||
<input type="text" class="form-control" id="name" aria-describedby="name" placeholder="" name="place">
|
||||
</div>
|
||||
|
||||
<div class="col-lg-12 form-group">
|
||||
<label for="order">Opis <span>*</span></label>
|
||||
<textarea class="form-control" id="order" rows="3" name="script"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-12 form-group">
|
||||
<div class="file-field">
|
||||
<span>Wybierz zdjęcie</span>
|
||||
<input name="file" type="file" accept="image/*">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-12 form-group">
|
||||
<input type="submit" class="btn btn-primary update_btn" value="Dodaj">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</form>
|
||||
<!--================End Track Area =================-->
|
||||
<!--================End Register Area =================-->
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-6">
|
||||
<div class="c_product_img">
|
||||
<img class="img-fluid" src="{% static "img/product/l-product-2.jpg" %}">
|
||||
<img class="img-fluid" src="{{ product.picture.url }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-8 col-md-6">
|
||||
|
@ -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)
|
||||
|
@ -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 = ""
|
||||
|
Loading…
Reference in New Issue
Block a user