update images

shop
Raz 8 months ago
parent 4345e5a8fd
commit 9a3b920058
  1. 3
      padelclub_backend/settings.py
  2. 32
      shop/management/commands/create_initial_shop_data.py
  3. 18
      shop/migrations/0015_alter_product_image.py
  4. 2
      shop/models.py
  5. BIN
      shop/static/shop/images/products/hat.jpg
  6. BIN
      shop/static/shop/images/products/hoodie_h.jpeg
  7. BIN
      shop/static/shop/images/products/tshirt_h.png
  8. 2
      shop/templates/shop/product_item.html
  9. 2
      tournaments/urls.py

@ -15,9 +15,6 @@ import os
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

@ -1,8 +1,6 @@
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from shop.models import Color, Size, Product from shop.models import Color, Size, Product
from django.core.files.base import ContentFile from django.conf import settings
import os
import urllib.request
class Command(BaseCommand): class Command(BaseCommand):
help = 'Creates initial data for the shop' help = 'Creates initial data for the shop'
@ -54,7 +52,7 @@ class Command(BaseCommand):
'cut': 2, # Men 'cut': 2, # Men
'colors': ['Black', 'White', 'Red'], 'colors': ['Black', 'White', 'Red'],
'sizes': ['M', 'L', 'XL'], 'sizes': ['M', 'L', 'XL'],
'image_url': 'https://example.com/images/tennis_racket.jpg' 'image_filename': 'hat.jpg' # Just the filename
}, },
{ {
'title': 'Sports T-Shirt', 'title': 'Sports T-Shirt',
@ -63,7 +61,7 @@ class Command(BaseCommand):
'cut': 1, # Women 'cut': 1, # Women
'colors': ['Black', 'White', 'Blue', 'Red'], 'colors': ['Black', 'White', 'Blue', 'Red'],
'sizes': ['XS', 'S', 'M', 'L', 'XL'], 'sizes': ['XS', 'S', 'M', 'L', 'XL'],
'image_url': 'https://example.com/images/tshirt.jpg' 'image_filename': 'tshirt.jpg' # Just the filename
}, },
{ {
'title': 'Kids Tennis Shorts', 'title': 'Kids Tennis Shorts',
@ -72,7 +70,7 @@ class Command(BaseCommand):
'cut': 3, # Kids 'cut': 3, # Kids
'colors': ['Blue', 'White'], 'colors': ['Blue', 'White'],
'sizes': ['XS', 'S', 'M'], 'sizes': ['XS', 'S', 'M'],
'image_url': 'https://example.com/images/kids_shorts.jpg' 'image_filename': 'kids_shorts.jpg' # Just the filename
} }
] ]
@ -97,17 +95,17 @@ class Command(BaseCommand):
for size_name in product_data['sizes']: for size_name in product_data['sizes']:
product.sizes.add(size_objects[size_name]) product.sizes.add(size_objects[size_name])
# Add image (commented out, use if needed) # Construct the full path for storage
""" if 'image_filename' in product_data and product_data['image_filename']:
try: # Construct the URL path to the image
result = urllib.request.urlretrieve(product_data['image_url']) # This uses STATIC_URL from your settings
product.image.save( image_path = f"{settings.STATIC_URL}shop/images/products/{product_data['image_filename']}"
os.path.basename(product_data['image_url']), print(image_path)
ContentFile(open(result[0], 'rb').read()) # Store this path in the database
) product.image = image_path
except Exception as e: product.save()
self.stdout.write(f'Error downloading image: {e}')
""" self.stdout.write(f'Added image path "{image_path}" for: {product_data["title"]}')
else: else:
self.stdout.write(f'Product already exists: {product_data["title"]}') self.stdout.write(f'Product already exists: {product_data["title"]}')

@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2025-03-20 17:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('shop', '0014_alter_size_name'),
]
operations = [
migrations.AlterField(
model_name='product',
name='image',
field=models.CharField(blank=True, max_length=200, null=True),
),
]

@ -28,7 +28,7 @@ class Size(models.Model):
class Product(models.Model): class Product(models.Model):
title = models.CharField(max_length=200) title = models.CharField(max_length=200)
image = models.ImageField(upload_to="products/", null=True, blank=True) image = models.CharField(max_length=200, null=True, blank=True)
price = models.DecimalField(max_digits=10, decimal_places=2, default=0.00) price = models.DecimalField(max_digits=10, decimal_places=2, default=0.00)
# Use string references to prevent circular imports # Use string references to prevent circular imports

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

@ -1,7 +1,7 @@
<div class="small-12 medium-6 large-3 my-block"> <div class="small-12 medium-6 large-3 my-block">
<div class="bubble"> <div class="bubble">
{% if product.image %} {% if product.image %}
<img src="{{ product.image.url }}" alt="{{ product.title }}" class="product-image"> <img src="{{ product.image }}" alt="{{ product.title }}" class="product-image">
{% else %} {% else %}
<div class="no-image">No Image Available</div> <div class="no-image">No Image Available</div>
{% endif %} {% endif %}

@ -78,5 +78,3 @@ urlpatterns = [
path('activation-success/', views.activation_success, name='activation_success'), path('activation-success/', views.activation_success, name='activation_success'),
path('activation-failed/', views.activation_failed, name='activation_failed'), path('activation-failed/', views.activation_failed, name='activation_failed'),
] ]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Loading…
Cancel
Save