109 lines
3.3 KiB
Python
109 lines
3.3 KiB
Python
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.urls import reverse
|
|
from users.models import Base_User
|
|
import users
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
class Offer_Category(models.Model):
|
|
id = models.AutoField(primary_key= True)
|
|
name = models.CharField(max_length=50)
|
|
|
|
class Meta:
|
|
verbose_name = 'Category'
|
|
verbose_name_plural = 'Categories'
|
|
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
STATUS = (
|
|
('Active',_('Active offer')),
|
|
('Inactive',_('Inactive offer')),
|
|
('Verification',_('Waiting for verication')),
|
|
('Blocked',_('Blocked Offer')),
|
|
)
|
|
|
|
DMC_Value = (
|
|
('B',_('Do 3.5 tony.')),
|
|
('C',_('Między 3.5 a 7.5 tony')),
|
|
('C1',_('Powyzej 7.5 tony')),
|
|
)
|
|
|
|
COOKER_Option = (
|
|
('Elecric',_('Kuchenka elektryczna')),
|
|
('Gas',_('Kuchenka gazowa')),
|
|
('None',_('Brak')),
|
|
)
|
|
|
|
GEARBOX_Option = (
|
|
('Manual',_('Skrzynia manualna')),
|
|
('Automat',_('Skrzynia automatyczna')),
|
|
)
|
|
class Offer(models.Model):
|
|
id = models.AutoField(primary_key= True)
|
|
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
|
date_added = models.DateTimeField(auto_now_add=True)
|
|
status = models.CharField(max_length=32, choices=STATUS, default='Inactive')
|
|
|
|
title = models.CharField(_("Title"), max_length=50,default='Tytuł oferty')
|
|
category = models.ForeignKey(Offer_Category ,default= None,on_delete= models.CASCADE)
|
|
price = models.DecimalField(max_digits=10, decimal_places=2)
|
|
DMC = models.CharField(max_length=32, choices=DMC_Value, default='B')
|
|
Places_to_sleep = models.IntegerField(default=2)
|
|
|
|
cooker = models.CharField(max_length = 32, choices=COOKER_Option, default='None')
|
|
fridge = models.BooleanField(default=False)
|
|
microwave = models.BooleanField(default= False)
|
|
Webasto = models.BooleanField(default=False)
|
|
auto_temp_control = models.BooleanField(default= False)
|
|
water_level_indicator = models.BooleanField(default=False)
|
|
battery_level = models.BooleanField(default=False)
|
|
photovoltaic_panels = models.BooleanField(default=False)
|
|
|
|
gearbox = models.CharField(max_length=32, choices=GEARBOX_Option,default='Manual')
|
|
tempomat = models.BooleanField(default=False)
|
|
|
|
class Meta:
|
|
pass
|
|
|
|
def __str__(self):
|
|
return self.id
|
|
|
|
def get_absolute_url(self):
|
|
return reverse('offer_detail', kwargs = {'pk': self.id })
|
|
|
|
|
|
|
|
def _upload_path(instance,filename):
|
|
return instance.get_upload_path(filename)
|
|
|
|
class Image_offer(models.Model):
|
|
offer = models.ForeignKey("Offer", verbose_name="", on_delete = models.CASCADE, default=None)
|
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
|
image = models.ImageField(upload_to=_upload_path, null = True, blank = True)
|
|
main_image = models.BooleanField(default= False)
|
|
|
|
def get_upload_path(self,filename):
|
|
return "uploads/user/id-"+str(self.user.id)+"/"+str(self.offer.id) + "/" +filename
|
|
|
|
def get_absolute_url(self):
|
|
return reverse("model_detail", kwargs={"pk": self.pk})
|
|
|
|
|
|
class Favourite_Offers(models.Model):
|
|
user = models.ForeignKey('users.Base_User', on_delete=models.CASCADE,)
|
|
offer = models.ForeignKey('Offer', on_delete=models.SET_NULL, null = True)
|
|
timestap = models.DateTimeField(auto_now_add=True, db_index=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|