Add dynamic adding imagefields

This commit is contained in:
Krzysztof Bonecki 2021-01-30 22:43:49 +01:00
parent 64cf510627
commit c1721595ee
465 changed files with 130 additions and 28 deletions

0
vagus/.DS_Store vendored Normal file → Executable file
View File

0
vagus/.bashrc_profile Normal file → Executable file
View File

0
vagus/camper/__init__.py Normal file → Executable file
View File

BIN
vagus/camper/__pycache__/__init__.cpython-37.pyc Normal file → Executable file

Binary file not shown.

0
vagus/camper/__pycache__/__init__.cpython-38.pyc Normal file → Executable file
View File

BIN
vagus/camper/__pycache__/admin.cpython-37.pyc Normal file → Executable file

Binary file not shown.

BIN
vagus/camper/__pycache__/forms.cpython-37.pyc Normal file → Executable file

Binary file not shown.

BIN
vagus/camper/__pycache__/models.cpython-37.pyc Normal file → Executable file

Binary file not shown.

0
vagus/camper/__pycache__/test.cpython-37.pyc Normal file → Executable file
View File

0
vagus/camper/__pycache__/tests.cpython-37.pyc Normal file → Executable file
View File

BIN
vagus/camper/__pycache__/urls.cpython-37.pyc Normal file → Executable file

Binary file not shown.

0
vagus/camper/__pycache__/views.cpython-37.pyc Normal file → Executable file
View File

0
vagus/camper/admin.py Normal file → Executable file
View File

0
vagus/camper/apps.py Normal file → Executable file
View File

18
vagus/camper/forms.py Normal file → Executable file
View File

@ -1,7 +1,9 @@
from django import forms
from django.forms import formset_factory
from .models import Offer,Offer_Category,Image_offer
from django.forms import BaseFormSet
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
class OfferCreateForm(forms.ModelForm):
title = forms.CharField(label = 'Offer title', max_length=50)
@ -12,9 +14,19 @@ class OfferCreateForm(forms.ModelForm):
class OfferImageCreateForm(forms.ModelForm):
image = forms.ImageField()
class Meta:
model = Image_offer
fields = ('image','main_image')
OfferImageFormSet = formset_factory(OfferImageCreateForm, extra = 2, max_num = 2)
class BaseOfferImageFormSet(BaseFormSet):
def clean(self):
if any(self.errors):
return
count = 0
for form in self.forms:
if form.cleaned_data['main_image']:
count += 1
if count > 1:
raise forms.ValidationError(_("Mozna ustawić tylko jedno zdjecie jako miniaturka."))
OfferImageFormSet = formset_factory(OfferImageCreateForm,formset = BaseOfferImageFormSet)

0
vagus/camper/migrations/0001_initial.py Normal file → Executable file
View File

0
vagus/camper/migrations/0002_auto_20210112_1748.py Normal file → Executable file
View File

0
vagus/camper/migrations/0003_offer_description.py Normal file → Executable file
View File

0
vagus/camper/migrations/__init__.py Normal file → Executable file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

5
vagus/camper/models.py Normal file → Executable file
View File

@ -93,12 +93,15 @@ def _upload_path(instance,filename):
class Image_offer(models.Model):
offer = models.ForeignKey("Offer", verbose_name="", on_delete = models.CASCADE, default=None, related_name='images')
image = models.ImageField(upload_to=_upload_path, null = True, blank = True)
image = models.ImageField(upload_to=_upload_path, null = False, blank = False)
main_image = models.BooleanField(default= False)
def get_upload_path(self,filename):
return "uploads/offer-images"+ "/" + 'id-'+str(self.offer.id) + "/" +filename
def delete(self,*args,**kwargs):
self.image.delete()
return super(Image_offer,self).save(*args,**kwargs)
class Favourite_Offers(models.Model):
user = models.ForeignKey('users.Base_User', on_delete=models.CASCADE,)

0
vagus/camper/test.py Normal file → Executable file
View File

0
vagus/camper/urls.py Normal file → Executable file
View File

0
vagus/camper/views/__init__.py Normal file → Executable file
View File

BIN
vagus/camper/views/__pycache__/__init__.cpython-37.pyc Normal file → Executable file

Binary file not shown.

Binary file not shown.

BIN
vagus/camper/views/__pycache__/detail_page.cpython-37.pyc Normal file → Executable file

Binary file not shown.

View File

View File

View File

Binary file not shown.

16
vagus/camper/views/create_offer.py Normal file → Executable file
View File

@ -72,13 +72,13 @@ class CreateOffer(CreateView):
except Exception:
offer.status = 'Inactive'
offer.save()
messages.success(request,'Dodaj zdjęcia aby przesłać ofertę do weryfikacji')
return redirect('/') #Redirect to offer page or user's offers list
messages.error(request,'Dodaj zdjęcia aby przesłać ofertę do weryfikacji')
return redirect('/') #Redirect to offe-update-page or user's offers list
messages.success(request,'Oferta utworzona i przesłana do weryfikacji')
return redirect('/') #Redirect to offer page or user's offers list
else:
messages.warning(request, 'Wprowadzone dane są nieprawidłowe.')
messages.error(request, 'Wprowadzone dane są nieprawidłowe.')
return render(request,'offer/add-offer.html', {'form': form, 'formset': formset} )
else:
form = OfferCreateForm()
@ -87,4 +87,12 @@ class CreateOffer(CreateView):
else:
messages.error(request, 'Nie masz uprawnień!')
return redirect('/') #Redirect to login / register page for owner
return redirect('/') #Redirect to login / register page for owner
class EditOffer(UpdateView):
def get(self,request,*args, **kwargs):
pass
def post(self,request,*args,**kwargs):
pass

0
vagus/camper/views/detail_page.py Normal file → Executable file
View File

0
vagus/camper/views/statistic_offer.py Normal file → Executable file
View File

0
vagus/media/avatars/default.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

Before

Width:  |  Height:  |  Size: 385 KiB

After

Width:  |  Height:  |  Size: 385 KiB

0
vagus/media/uploads/offer-images/id-1/IMG_8099.jpg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View File

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 125 KiB

View File

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

View File

Before

Width:  |  Height:  |  Size: 210 KiB

After

Width:  |  Height:  |  Size: 210 KiB

View File

Before

Width:  |  Height:  |  Size: 210 KiB

After

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

View File

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 125 KiB

View File

Before

Width:  |  Height:  |  Size: 194 KiB

After

Width:  |  Height:  |  Size: 194 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 125 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

Before

Width:  |  Height:  |  Size: 124 KiB

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

0
vagus/media/uploads/offer-images/id-2/data.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

Before

Width:  |  Height:  |  Size: 210 KiB

After

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

View File

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

View File

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View File

Before

Width:  |  Height:  |  Size: 385 KiB

After

Width:  |  Height:  |  Size: 385 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

View File

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Some files were not shown because too many files have changed in this diff Show More