file upload default
This commit is contained in:
parent
acbca41040
commit
cc13e9666d
|
@ -0,0 +1 @@
|
||||||
|
media/
|
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"python.pythonPath": "C:\\ProgramData\\Anaconda3\\python.exe"
|
"python.pythonPath": "C:\\Python39\\python.exe"
|
||||||
}
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -25,11 +25,11 @@ class BidForm(forms.Form):
|
||||||
bid = forms.DecimalField(decimal_places=2)
|
bid = forms.DecimalField(decimal_places=2)
|
||||||
|
|
||||||
class CreateForm(forms.Form):
|
class CreateForm(forms.Form):
|
||||||
title = forms.CharField( max_length=100, widget=forms.TextInput(attrs={'placeholder': 'title'}))
|
title = forms.CharField( max_length=100, widget=forms.TextInput(attrs={'placeholder': 'title'}),required=True)
|
||||||
desc= forms.CharField(max_length=100,widget=forms.TextInput(attrs={'placeholder': 'description'}))
|
desc= forms.CharField(max_length=100,widget=forms.TextInput(attrs={'placeholder': 'description'}),required=True)
|
||||||
starting_bid= forms.IntegerField(widget=forms.TextInput(attrs={'placeholder': 'Starting bid'}))
|
starting_bid= forms.DecimalField(decimal_places=2,widget=forms.TextInput(attrs={'placeholder': 'Starting bid'}), required=True)
|
||||||
category = forms.ChoiceField(choices=categories)
|
category = forms.ChoiceField(choices=categories,required=True)
|
||||||
photo = forms.ImageField()
|
photo = forms.ImageField(required=False)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(CreateForm, self).__init__(*args, **kwargs)
|
super(CreateForm, self).__init__(*args, **kwargs)
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -20,7 +20,7 @@ class AuctionListing(models.Model):
|
||||||
user = models.ForeignKey(User,on_delete = models.CASCADE)
|
user = models.ForeignKey(User,on_delete = models.CASCADE)
|
||||||
price = models.DecimalField(max_digits = 10,decimal_places = 2)
|
price = models.DecimalField(max_digits = 10,decimal_places = 2)
|
||||||
desc = models.CharField(max_length = 1000)
|
desc = models.CharField(max_length = 1000)
|
||||||
picture = models.ImageField();
|
picture = models.ImageField(default='default.png');
|
||||||
category = models.CharField(max_length = 64,choices=category_choices)
|
category = models.CharField(max_length = 64,choices=category_choices)
|
||||||
date_added = models.DateTimeField(auto_now_add=True)
|
date_added = models.DateTimeField(auto_now_add=True)
|
||||||
closed = models.BooleanField(default=False)
|
closed = models.BooleanField(default=False)
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<a href="listing/{{ listing.title}}" style = "color:inherit;text-decoration: none;">
|
<a href="listing/{{ listing.title}}" style = "color:inherit;text-decoration: none;">
|
||||||
<div class="card border-light" style="width: 18rem;">
|
<div class="card border-light" style="width: 18rem;">
|
||||||
<div class="shadow p-2 mb-2 bg-white rounded">
|
<div class="shadow p-2 mb-2 bg-white rounded">
|
||||||
<img class="card-img-top" src="{{ listing.picture }}" alt="Preview not found">
|
<img class="card-img-top" src="{{ listing.picture.url }}" alt="Preview not found">
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<a href="listing/{{list.title}}" style = "color:inherit;text-decoration: none;">
|
<a href="listing/{{list.title}}" style = "color:inherit;text-decoration: none;">
|
||||||
<div class="card border-light" style="width: 18rem;">
|
<div class="card border-light" style="width: 18rem;">
|
||||||
<div class="shadow p-2 mb-2 bg-white rounded">
|
<div class="shadow p-2 mb-2 bg-white rounded">
|
||||||
<img class="card-img-top" src="{{ list.picture }}" alt="Preview not found">
|
<img class="card-img-top" src="{{ list.picture.url }}" alt="Preview not found">
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<a href="listing/{{ listing.title}}" style = "color:inherit;text-decoration: none;">
|
<a href="listing/{{ listing.title}}" style = "color:inherit;text-decoration: none;">
|
||||||
<div class="card border-light" style="width: 18rem;">
|
<div class="card border-light" style="width: 18rem;">
|
||||||
<div class="shadow p-2 mb-2 bg-white rounded">
|
<div class="shadow p-2 mb-2 bg-white rounded">
|
||||||
<img class="card-img-top" src="{{ listing.picture }}" alt="Preview not found">
|
<img class="card-img-top" src="{{ listing.picture.url }}" alt="Preview not found">
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
{% if user.is_authenticated and user != Listing.user %}
|
{% if user.is_authenticated and user != Listing.user %}
|
||||||
<form action="{% url 'bid' Listing.title %}" method = "POST">
|
<form action="{% url 'bid' Listing.title %}" method = "POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ bid_form }}
|
{{ bid_form.as_p }}
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
<input class="btn btn-primary" type="submit" value="Place Bid">
|
<input class="btn btn-primary" type="submit" value="Place Bid">
|
||||||
|
|
|
@ -7,9 +7,7 @@ from django import forms
|
||||||
from .models import User,AuctionListing,Comment,Bids
|
from .models import User,AuctionListing,Comment,Bids
|
||||||
from .forms import BidForm,CreateForm
|
from .forms import BidForm,CreateForm
|
||||||
|
|
||||||
|
categories=["Fashion","Electronics","Home","Sports","Toys","Automobile","Books","Videogames","Others"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def watch(request,title):
|
def watch(request,title):
|
||||||
"""
|
"""
|
||||||
|
@ -165,6 +163,9 @@ def create(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = CreateForm(request.POST, request.FILES)
|
form = CreateForm(request.POST, request.FILES)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
if not form.cleaned_data["photo"]:
|
||||||
|
listing_obj = AuctionListing(title = form.cleaned_data["title"], desc =form.cleaned_data["desc"], user = request.user,price = form.cleaned_data["starting_bid"],category= form.cleaned_data["category"])
|
||||||
|
else:
|
||||||
listing_obj = AuctionListing(title = form.cleaned_data["title"], desc =form.cleaned_data["desc"], user = request.user,price = form.cleaned_data["starting_bid"], picture = form.cleaned_data["photo"],category= form.cleaned_data["category"])
|
listing_obj = AuctionListing(title = form.cleaned_data["title"], desc =form.cleaned_data["desc"], user = request.user,price = form.cleaned_data["starting_bid"], picture = form.cleaned_data["photo"],category= form.cleaned_data["category"])
|
||||||
listing_obj.save()
|
listing_obj.save()
|
||||||
bid_obj = Bids(bid_value = form.cleaned_data["starting_bid"], listing = listing_obj, user = request.user)
|
bid_obj = Bids(bid_value = form.cleaned_data["starting_bid"], listing = listing_obj, user = request.user)
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
from storages.backends.azure_storage import AzureStorage
|
||||||
|
|
||||||
|
class AzureMediaStorage(AzureStorage):
|
||||||
|
account_name = 'auctionimages' # Must be replaced by your <storage_account_name>
|
||||||
|
account_key = '3W/fel22r8ExgQMDr8KOxxklp80/slPtAznb+G1Hkq0DWuX2bOIXnQMpgmU/BIJdIWnbDsgMr2SbC5l9qfJJ6g==' # Must be replaced by your <storage_account_key>
|
||||||
|
azure_container = 'media'
|
||||||
|
expiration_secs = None
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
from storages.backends.s3boto3 import S3Boto3Storage
|
|
||||||
|
|
||||||
class MediaStorage(S3Boto3Storage):
|
|
||||||
location = 'media'
|
|
||||||
file_overwrite = False
|
|
|
@ -124,3 +124,9 @@ STATIC_URL = '/static/'
|
||||||
|
|
||||||
MEDIA_URL = '/media/'
|
MEDIA_URL = '/media/'
|
||||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||||
|
|
||||||
|
STATICFILES_DIRS = [
|
||||||
|
os.path.join(BASE_DIR, 'auctions/static'),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,3 +25,18 @@ urlpatterns = [
|
||||||
|
|
||||||
if settings.DEBUG: # new
|
if settings.DEBUG: # new
|
||||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# # alternate photo to display
|
||||||
|
# if photo_url == "":
|
||||||
|
# photo_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/No_image_available_600_x_450.svg/1280px-No_image_available_600_x_450.svg.png"
|
||||||
|
# category_value = request.POST["category"]
|
||||||
|
# listing_obj = AuctionListing(title = title, desc = desc, user = request.user,price = starting_bid, picture = photo_url,category=category_value)
|
||||||
|
# listing_obj.save()
|
||||||
|
# bid_obj = Bids(bid_value = starting_bid, listing = listing_obj, user = request.user)
|
||||||
|
# bid_obj.save()
|
||||||
|
# return render(request,"auctions/index.html",{
|
||||||
|
# "Listings" : AuctionListing.objects.all()
|
||||||
|
# })
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 7.1 KiB |
Loading…
Reference in New Issue