summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2019-11-09 20:01:48 -0500
committerluxagraf <sng@luxagraf.net>2019-11-09 20:01:48 -0500
commit6bccb82f7751d8c126f0342ccc97ff5311fa2ed6 (patch)
treea8edc365b6ee615fe647452450551bc085455956 /app
parent3005097a5e8871a46e7e8f87dd2d4c9766686cdf (diff)
finished up product insert template
Diffstat (limited to 'app')
-rw-r--r--app/products/admin.py8
-rw-r--r--app/products/migrations/0004_auto_20191109_0849.py23
-rw-r--r--app/products/migrations/0005_product_featured_image.py20
-rw-r--r--app/products/migrations/0006_remove_product_image.py17
-rw-r--r--app/products/models.py12
-rw-r--r--app/products/templates/products/snippet.html53
6 files changed, 110 insertions, 23 deletions
diff --git a/app/products/admin.py b/app/products/admin.py
index d8059f2..3a26358 100644
--- a/app/products/admin.py
+++ b/app/products/admin.py
@@ -1,15 +1,21 @@
from django.contrib import admin
+
from .models import Brand, Product
+from utils.widgets import AdminImageWidget, LGEntryForm
@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
+ form = LGEntryForm
list_display = ('name', 'admin_thumbnail', 'rating', 'pub_date')
search_fields = ['name', 'body_markdown']
list_filter = ('rating', 'pub_date')
class Media:
- js = ('next-prev-links.js',)
+ js = ('image-loader.js', 'next-prev-links.js')
+ css = {
+ "all": ("my_styles.css",)
+ }
@admin.register(Brand)
diff --git a/app/products/migrations/0004_auto_20191109_0849.py b/app/products/migrations/0004_auto_20191109_0849.py
new file mode 100644
index 0000000..1666a56
--- /dev/null
+++ b/app/products/migrations/0004_auto_20191109_0849.py
@@ -0,0 +1,23 @@
+# Generated by Django 2.2.6 on 2019-11-09 08:49
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('products', '0003_auto_20191008_0941'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='product',
+ name='primary_offer_retailer',
+ field=models.IntegerField(choices=[(0, 'Amazon'), (1, 'REI'), (2, 'eBay')], default=0),
+ ),
+ migrations.AlterField(
+ model_name='product',
+ name='secondary_offer_retailer',
+ field=models.IntegerField(choices=[(0, 'Amazon'), (1, 'REI'), (2, 'eBay')], default=0),
+ ),
+ ]
diff --git a/app/products/migrations/0005_product_featured_image.py b/app/products/migrations/0005_product_featured_image.py
new file mode 100644
index 0000000..91e37b0
--- /dev/null
+++ b/app/products/migrations/0005_product_featured_image.py
@@ -0,0 +1,20 @@
+# Generated by Django 2.2.6 on 2019-11-09 09:35
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('photos', '0019_auto_20190704_0903'),
+ ('products', '0004_auto_20191109_0849'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='product',
+ name='featured_image',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='photos.LuxImage'),
+ ),
+ ]
diff --git a/app/products/migrations/0006_remove_product_image.py b/app/products/migrations/0006_remove_product_image.py
new file mode 100644
index 0000000..b05110d
--- /dev/null
+++ b/app/products/migrations/0006_remove_product_image.py
@@ -0,0 +1,17 @@
+# Generated by Django 2.2.6 on 2019-11-09 09:47
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('products', '0005_product_featured_image'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='product',
+ name='image',
+ ),
+ ]
diff --git a/app/products/models.py b/app/products/models.py
index bf33db4..d4dd5a8 100644
--- a/app/products/models.py
+++ b/app/products/models.py
@@ -10,6 +10,7 @@ from django.utils.html import format_html
from django.conf import settings
from django.template.defaultfilters import slugify
+from photos.models import PhotoGallery, LuxImage, LuxImageSize
from photos.utils import resize_image
from utils.util import render_images, render_products, parse_video, markdown_to_html
@@ -32,15 +33,20 @@ class Product(models.Model):
pub_date = models.DateTimeField()
body_markdown = models.TextField(blank=True)
body_html = models.TextField(null=True, blank=True)
- primary_offer_retailer = models.CharField(max_length=400)
+ RETAILER = (
+ (0, 'Amazon'),
+ (1, 'REI'),
+ (2, 'eBay'),
+ )
+ primary_offer_retailer = models.IntegerField(choices=RETAILER, default=0)
primary_offer_url = models.CharField(max_length=400)
primary_offer_price = models.IntegerField()
- secondary_offer_retailer = models.CharField(max_length=400)
+ secondary_offer_retailer = models.IntegerField(choices=RETAILER, default=0)
secondary_offer_url = models.CharField(max_length=400, blank=True, null=True)
secondary_offer_price = models.IntegerField(blank=True, null=True)
rating = models.IntegerField()
is_public = models.BooleanField(default=True)
- image = models.FileField(upload_to=get_upload_path, null=True, blank=True)
+ featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True)
class Meta:
ordering = ('-pub_date',)
diff --git a/app/products/templates/products/snippet.html b/app/products/templates/products/snippet.html
index be5d874..3fc9f6f 100644
--- a/app/products/templates/products/snippet.html
+++ b/app/products/templates/products/snippet.html
@@ -1,26 +1,41 @@
-<div itemscope itemtype="http://schema.org/Product">
+{% load get_image_by_size %}
+{% load get_image_width %}
+{% with image=object.featured_image %}
+<div itemscope itemtype="http://schema.org/Product" class="product-card">
<meta itemprop="brand" content="{{object.brand.name}}" />
- <h4 class="product-link" itemprop="name">{{object.get_full_name}}: (<span itemprop="offers" itemscope itemtype="http://schema.org/Offer">
- <a href="{{object.primary_offer_url}}" title="buy the {{object.get_full_name}} for ${{object.primary_offer_price}}" itemprop="url" rel="nofollow">
- <span itemprop="priceCurrency" content="USD">$</span><span
- itemprop="price" content="{{object.primary_offer_price}}">{{object.primary_offer_price}}</span> {{object.primary_offer_retailer}}</a>
- <link itemprop="availability" href="http://schema.org/InStock" />
- </span>)
- {% if object.secondary_offer_url %}(<span itemprop="offers" itemscope itemtype="http://schema.org/Offer">
- <a href="{{object.secondary_offer_url}}" title="buy the {{object.get_full_name}} for ${{object.secondary_offer_price}}" itemprop="url">
- <span itemprop="priceCurrency" content="USD">$</span><span
- itemprop="price" content="{{object.secondary_offer_price}}">{{object.secondary_offer_price}}</span> {{object.secondary_offer_retailer}}</a>
- <link itemprop="availability" href="http://schema.org/InStock" />
- </span>){% endif %}</h4>
- <div itemprop="review" itemscope itemtype="http://schema.org/Review">
- <meta itemprop="name" content="{{object.get_full_name}}" />
- <meta itemprop="author" content="Scott Gilbertson" />
- <meta itemprop="datePublished" content="{{object.pub_date}}" />
- <span itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
+ <figure itemscope itemtype="http://schema.org/ImageObject" class="picfull">
+ <a href="{% get_image_by_size image 'original' %}" title="view larger image">
+ <img class="u-photo" itemprop="contentUrl" sizes="(max-width: 750px) 100vw, (min-width: 751) 750px" srcset="{% for size in image.sizes.all%}{% get_image_by_size image size.name %} {{size.width}}w{% if forloop.last%}"{%else%}, {%endif%}{%endfor%}{% for size in image.sizes.all%}{%if not forloop.first and not forloop.last%} src="{% get_image_by_size image size.name%}"{%endif%}{%endfor%} alt="{{image.alt}} photographed by {% if image.photo_credit_source %}{{image.photo_credit_source}}{%else%}luxagraf{%endif%}" >
+ </a>
+ <figcaption>{% if image.caption %}{{image.caption|safe}}{% endif %}{% if image.photo_credit_source %}{%if image.caption %} | {%endif%}image: {% if image.photo_credit_url %}<a href="{{image.photo_credit_url}}" itemprop="author">{%endif%}{{image.photo_credit_source|lower}}{% if image.photo_credit_url %}</a>{%endif%}{%endif%}
+ </figcaption>
+ </figure>
+ <div class="buy-btn-wrapper">
+ <h4 class="product-header" itemprop="name">{{object.get_full_name}}</h4>
+ <h5 class="product-link" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
+ <a href="{{object.primary_offer_url}}" title="buy the {{object.get_full_name}} for ${{object.primary_offer_price}} from {{object.primary_offer_retailer.get_primary_offer_retailer_display}}" itemprop="url" rel="nofollow">
+ Buy Now ({{object.get_primary_offer_retailer_display}}
+ <span itemprop="priceCurrency" content="USD">$</span><span itemprop="price" content="{{object.primary_offer_price}}">{{object.primary_offer_price}}</span>)
+ </a>
+ <link itemprop="availability" href="http://schema.org/InStock" />
+ </h5>{% if object.secondary_offer_url %}
+ <h5 class="product-link" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
+ <a href="{{object.secondary_offer_url}}" title="buy the {{object.get_full_name}} for ${{object.secondary_offer_price}} from {{object.secondary_offer_retailer.get_secondary_offer_retailer_display}}" itemprop="url">
+ Buy Now ({{object.get_secondary_offer_retailer_display}}
+ <span itemprop="priceCurrency" content="USD">$</span><span itemprop="price" content="{{object.secondary_offer_price}}">{{object.secondary_offer_price}}</span>)
+ </a>
+ <link itemprop="availability" href="http://schema.org/InStock" />
+ </h5>{% endif %}
+ </div>
+ <span itemprop="review" itemscope itemtype="http://schema.org/Review">
+ <meta itemprop="name" content="{{object.get_full_name}}" />
+ <meta itemprop="author" content="Scott Gilbertson" />
+ <meta itemprop="datePublished" content="{{object.pub_date}}" />
+ <span itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
<meta itemprop="worstRating" content = "1"/>
<meta itemprop="ratingValue" content="{{object.rating}}" />
<meta itemprop="bestRating" content="10" />
</span>
<meta itemprop="description" content="{{object.body_markdown}}" />
- </div>
</div>
+{% endwith %}