import os
from records import models as rec_models
-from cartridge.shop.models import Product, ProductOption, Category
+from cartridge.shop.models import Product, ProductVariation, Category, ProductImage
from diggersdigest import settings
self.stdout.write("\t%d new country objects" % count)
self.stdout.write("\t%d countries in DB ( %d in old DB)" % (len(Country.objects.all()), len(old_country)))
-
+
# PODCAST FROM MIX
def populate_podcast(self, user):
MIX_CATEGORY = 'Podcast'
blog_models.BlogCategory.objects.get_or_create(title=MIX_CATEGORY)
-
+
PODCAST_IMG_PATH = os.path.join('uploads/blog/mixes')
PODCAST_AUDIO_PATH = os.path.join('uploads/audio/mixes')
obj.status=mix.published+1
obj.featured_image=img_path
obj.save()
-
+
self.stdout.write("\t%d new Podcast objects" % count)
self.stdout.write("\t%d Podcast in DB ( %d in old DB)" % (len(rec_models.Podcast.objects.all()), len(ordered_mix_list)))
## )
## #obj.delete()
## #obj.description= "Fill in the form below to get in touch with us."
-
+
# NEWS
def populate_news(self):
## news fields :
except AttributeError:
d = ''
print n.titre, ' - ', d
-
+
# Theme -> Category
def populate_category(self):
#
+ shop_cat, created = Category.objects.get_or_create(title="Shop")
+
theme_list = [theme for theme in rec_models.Theme.objects.all() if theme.published==1]
count = 0
for theme in theme_list:
- obj, create = Category.objects.get_or_create(pk=theme.id,
- title = theme.nom)
+ obj, create = Category.objects.get_or_create(pk=theme.id)
+ obj.title = theme.nom
+ obj.parent = shop_cat
+ obj.save()
if create:
count +=1
-
+
self.stdout.write('Category\n-------\n')
self.stdout.write("\t%d new Category objects" % count)
AUDIO_PATH = 'uploads/audio/'
RECORDS_PATH = os.path.join(AUDIO_PATH, "records")
-
+ IMG_PATH = os.path.join('uploads/product')
shop_list = rec_models.Shop.objects.all()
-
+
+
for shop in shop_list:
obj, created = rec_models.Record.objects.get_or_create(pk=shop.id)
obj.country = rec_models.Country.objects.get(name = shop.pays)
obj.audio_file = os.path.join(RECORDS_PATH, shop.mp3)
# product_id --> FK
-
+
obj.release_year , obj.release_decade = get_year(shop.date)
obj.date_text = shop.date # To be deleted later ?
obj.record_status = shop.new
+ obj.cover_condition_id = shop.cover
+ obj.vinyl_condition_id = shop.vinyl
obj.label = rec_models.Label.objects.get(name = shop.label)
obj.artist = rec_models.Artist.objects.get(name = shop.artiste)
obj.save()
theme = rec_models.Theme.objects.get(id=shop.theme)
if (theme.published == 1) and (shop.published==1):
- prod_obj, prod_created = Product.objects.get_or_create(pk=shop.id,
- site_id=1)
-
+ prod_obj, prod_created = Product.objects.get_or_create(
+ title=obj.title,
+ content = shop.desc)
if shop.devise == 3: #Euros
prod_obj.unit_price = shop.prix
elif shop.devise == 1: # Dollar
category = Category.objects.get(pk=shop.theme)
prod_obj.categories.add(category)
+ prodvar = ProductVariation.objects.get_or_create(product=prod_obj,
+ default=True)
+
prod_obj.save()
obj.product = prod_obj
obj.save()
-
+
+ img_file = os.path.join(IMG_PATH, str(shop.pk)+'.jpg')
+ abs_img_file = os.path.join(settings.MEDIA_ROOT, img_file)
+ if os.path.exists(abs_img_file):
+ image, created = ProductImage.objects.get_or_create(
+ file=img_file,
+ product=prod_obj)
+
self.stdout.write('Product %d / %d --> %s' % (prod_obj.pk,len(shop_list), prod_obj.available))
-
+
#self.stdout.write('\b\b\b\b%.4d' % obj.pk)
#print obj.__dict__
digger, created = auth_models.User.objects.get_or_create(username=u'digger',
password=u'admin',
is_staff=True,
- email=u'')
+ email=u'')
self.populate_category()
self.populate_label()
#self.populate_pages()
#self.populate_news()
- self.populate_record()
+ #self.populate_record()
print "Create new GradingCondition : %s" % obj.name
count += 1
- for option in settings.SHOP_OPTION_TYPE_CHOICES:
- option_obj, option_created = ProductOption.objects.get_or_create(type=option[0],
- name=grade.nom)
print "%d fiches GradingCondition crées" % count
-
--- /dev/null
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('records', '0005_auto_20150904_1309'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='record',
+ name='cover_condition',
+ field=models.ForeignKey(related_name='records_cover_condition', on_delete=django.db.models.deletion.SET_NULL, verbose_name='cover condition', to='records.ConditionGrading', null=True),
+ ),
+ migrations.AddField(
+ model_name='record',
+ name='vinyl_condition',
+ field=models.ForeignKey(related_name='records_vinyl_condition', on_delete=django.db.models.deletion.SET_NULL, verbose_name='vinyl condition', to='records.ConditionGrading', null=True),
+ ),
+ ]
(ON_HOLD, 'On Hold'),
(JUST_SOLD, 'Just Sold')
)
-
+
YEAR_START = 1920
YEAR_STOP = datetime.datetime.now().year + 10
release_decade = models.IntegerField(_('release decade'), null=True, choices=DECADE_CHOICES)
date_text = models.CharField(_('date text'), max_length=8, null=True)
country = models.ForeignKey(Country, verbose_name=_('country'), related_name='records', null=True, on_delete=models.SET_NULL)
- #cover_state = models.ForeignKey(ConditionGrading, verbose_name=_('cover condition'), related_name='records_cover_condition', null=True, on_delete=models.SET_NULL)
- #vinyl_state = models.ForeignKey(ConditionGrading, verbose_name=_('vinyl condition'), related_name='records_vinyl_condition', null=True, on_delete=models.SET_NULL)
+ cover_condition = models.ForeignKey(ConditionGrading, verbose_name=_('cover condition'), related_name='records_cover_condition', null=True, on_delete=models.SET_NULL)
+ vinyl_condition = models.ForeignKey(ConditionGrading, verbose_name=_('vinyl condition'), related_name='records_vinyl_condition', null=True, on_delete=models.SET_NULL)
audio_file = FileField(_("audio file"), max_length=1024, format="audio",
upload_to=upload_to("records.Record.audio", "audio/records"), null=True)
product = models.ForeignKey(Product, verbose_name=_('product'), related_name='records', null=True, on_delete=models.SET_NULL)