diff options
author | luxagraf <sng@luxagraf.net> | 2023-06-30 15:10:01 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2023-06-30 15:10:01 -0500 |
commit | 3d2cc4ef62465699ccc09747c65fb117e11502e9 (patch) | |
tree | c74c781bcb04131595c5a5c3a42c6944a4aeb0ff | |
parent | 194eccad7db0c16c36c48e2e5958dd25c1154437 (diff) |
seperated out brands and made buttons to copy code
-rw-r--r-- | app/deals/admin.py | 11 | ||||
-rw-r--r-- | app/deals/migrations/0011_brand.py | 23 | ||||
-rw-r--r-- | app/deals/migrations/0012_rename_brand_deal_brand_str.py | 18 | ||||
-rw-r--r-- | app/deals/migrations/0013_deal_brand.py | 19 | ||||
-rw-r--r-- | app/deals/models.py | 14 | ||||
-rw-r--r-- | app/deals/templates/deals/deal_detail.html | 62 |
6 files changed, 142 insertions, 5 deletions
diff --git a/app/deals/admin.py b/app/deals/admin.py index dcf629f..74a5b13 100644 --- a/app/deals/admin.py +++ b/app/deals/admin.py @@ -4,13 +4,18 @@ from django.contrib.gis.admin import OSMGeoAdmin from django.contrib.contenttypes.admin import GenericStackedInline from django_admin_listfilter_dropdown.filters import DropdownFilter, RelatedDropdownFilter, ChoiceDropdownFilter -from .models import Deal +from .models import Deal, Brand @admin.register(Deal) class DealAdmin(OSMGeoAdmin): - list_display = ('brand', 'title', 'category', 'deal_price', 'original_price', 'discount_percent', 'promo_type', 'amazon_link', 'search_ccc', 'search_wired', 'get_airtable_code') + list_display = ('brand_str', 'brand', 'title', 'category', 'deal_price', 'original_price', 'discount_percent', 'promo_type', 'amazon_link', 'search_ccc', 'search_wired', 'get_airtable_code') search_fields = ['brand', 'title', ] - list_filter = ('category', 'promo_type', ('brand', DropdownFilter),) + list_filter = ('category', 'promo_type', ('brand_str', DropdownFilter),) +@admin.register(Brand) +class BrandAdmin(OSMGeoAdmin): + list_display = ('name',) + search_fields = ['name' ] + diff --git a/app/deals/migrations/0011_brand.py b/app/deals/migrations/0011_brand.py new file mode 100644 index 0000000..07811b5 --- /dev/null +++ b/app/deals/migrations/0011_brand.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.2 on 2023-06-30 12:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('deals', '0010_alter_deal_discount_percent_str'), + ] + + operations = [ + migrations.CreateModel( + name='Brand', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ], + options={ + 'ordering': ('name',), + }, + ), + ] diff --git a/app/deals/migrations/0012_rename_brand_deal_brand_str.py b/app/deals/migrations/0012_rename_brand_deal_brand_str.py new file mode 100644 index 0000000..63e5566 --- /dev/null +++ b/app/deals/migrations/0012_rename_brand_deal_brand_str.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.2 on 2023-06-30 12:58 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('deals', '0011_brand'), + ] + + operations = [ + migrations.RenameField( + model_name='deal', + old_name='brand', + new_name='brand_str', + ), + ] diff --git a/app/deals/migrations/0013_deal_brand.py b/app/deals/migrations/0013_deal_brand.py new file mode 100644 index 0000000..e1430fa --- /dev/null +++ b/app/deals/migrations/0013_deal_brand.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.2 on 2023-06-30 12:59 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('deals', '0012_rename_brand_deal_brand_str'), + ] + + operations = [ + migrations.AddField( + model_name='deal', + name='brand', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='deals.brand'), + ), + ] diff --git a/app/deals/models.py b/app/deals/models.py index f3c3e12..ae2f92e 100644 --- a/app/deals/models.py +++ b/app/deals/models.py @@ -6,10 +6,22 @@ from django.dispatch import receiver from django.contrib.gis.db import models from django.utils.html import format_html, format_html_join + +class Brand(models.Model): + name = models.CharField(max_length=200) + + class Meta: + ordering = ('name',) + + def __str__(self): + return self.name + + class Deal(models.Model): + brand = models.ForeignKey(Brand, on_delete=models.CASCADE, null=True) asin = models.CharField(max_length=200) category = models.CharField(max_length=200) - brand = models.CharField(max_length=200) + brand_str = models.CharField(max_length=200) title = models.CharField(max_length=200, blank=True, null=True) prime_only = models.BooleanField(default=True) promo_type = models.CharField(max_length=200, blank=True) diff --git a/app/deals/templates/deals/deal_detail.html b/app/deals/templates/deals/deal_detail.html index 0d68d8a..804479f 100644 --- a/app/deals/templates/deals/deal_detail.html +++ b/app/deals/templates/deals/deal_detail.html @@ -1,5 +1,65 @@ {% load humanize %} - +<html> + <head> +<style> +body { + padding-top: 30px; +} +.button { + color: white; + padding: 1rem; + text-decoration: none; + background-color: #2ea44f; + border: 1px solid rgba(27, 31, 35, .15); + border-radius: 6px; + box-shadow: rgba(27, 31, 35, .1) 0 1px 0; + box-sizing: border-box; + color: #fff; + cursor: pointer; + display: inline-block; + font-family: -apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"; + font-size: 14px; + font-weight: 600; + line-height: 20px; + padding: 6px 16px; + position: relative; + text-align: center; + text-decoration: none; + user-select: none; + -webkit-user-select: none; + touch-action: manipulation; + vertical-align: middle; + white-space: nowrap; +} +</style> + </head> + <body> +<a class="button" href="#" onclick="CopyToClipboard('rich-text');return false;">Copy Rich Text</a> +<a class="button" href="#" onclick="CopyToClipboard('markdown');return false;">Copy Markdown</a> +<div id="rich-text"> <h4><a href="{{object.url}}">{{object.title|title}} for ${{object.get_deal_price_pretty|intcomma}} (${{object.dollars_off}} off)</a></h4> +</div> + +<textarea id="markdown" style="min-width: 35rem; height: 15rem;"> +#### [{{object.title|title}} for ${{object.get_deal_price_pretty|intcomma}} (${{object.dollars_off}} off)]({{object.url}}) + ++++button-group + +[Amazon]({{object.url}} "Amazon"){: target="_blank"} ++++ +</textarea> +<script> +function CopyToClipboard(id) +{ +var r = document.createRange(); +r.selectNode(document.getElementById(id)); +window.getSelection().removeAllRanges(); +window.getSelection().addRange(r); +document.execCommand('copy'); +window.getSelection().removeAllRanges(); +} +</script> +</body> +</html> |