1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
import datetime
import os
from django.dispatch import receiver
from django.contrib.gis.db import models
from django.utils.html import format_html, format_html_join
class Deal(models.Model):
asin = models.CharField(max_length=200)
category = models.CharField(max_length=200)
brand = 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)
deal_price = models.CharField(max_length=12, null=True)
original_price = models.CharField(max_length=12, null=True)
discount_percent = models.CharField(max_length=12, null=True)
discount_percent_num = models.FloatField(null=True)
url = models.CharField(max_length=200)
class Meta:
ordering = ('title',)
def __str__(self):
return self.title
def amazon_link(self):
return format_html('<a target="_blank" href="%s">%s</a>' % (self.url, self.url))
admin_link.short_description = 'Link'
def search_wired(self):
term = "https://www.google.com/search?q=%s" % (str(self.title))
term = term+"+site%3Awired.com"
return format_html("<a target='_blank' href='%s'>wired search</a>" % (term))
admin_link.short_description = 'Link'
"""
import csv
path = "pdelectronicsdata.csv"
with open(path) as f:
reader = csv.reader(f)
count = 0
for row in reader:
price = f'{num(row[10]):.2f}'
if row[5] == "Y":
prime = True
else:
prime = False
_, created = Deal.objects.get_or_create(
print(row)
count = 1
asin=row[0],
cateogry=row[1],
brand=row[2],
title=row[4],
prime_only=row[5],
promo_type=row[6],
deal_price= Decimal(price),
discount_percent=row[13],
url=row[14],
)
print(row[0], row[1], row[2], row[4],row[5],row[6],row[10],row[13],row[14])
title, prime_only, promo_type, deal_price, discount_percent, url)
_, created = Deal.objects.get_or_create(
asin=row[0],
cateogry=row[1],
brand=row[2],
title=row[4],
prime_only=row[5],
prime_only=row[6],
deal_price=row[10],
discount_percent=row[13],
url=row[14],
)
# creates a tuple of the new object or
# current object and a boolean of if it was created
"""
|