]> git.parisson.com Git - diggersdigest.git/commitdiff
Models : Change Record-Product relation to OneToOneField
authorThomas Fillon <thomas@parisson.com>
Wed, 9 Sep 2015 09:07:33 +0000 (11:07 +0200)
committerThomas Fillon <thomas@parisson.com>
Wed, 9 Sep 2015 09:07:33 +0000 (11:07 +0200)
diggersdigest/records/admin.py
diggersdigest/records/management/commands/populate_db.py
diggersdigest/records/migrations/0007_record_image.py [new file with mode: 0644]
diggersdigest/records/migrations/0008_auto_20150909_0818.py [new file with mode: 0644]
diggersdigest/records/migrations/0009_remove_record_image.py [new file with mode: 0644]
diggersdigest/records/models.py
diggersdigest/templates/pages/category.html
diggersdigest/templates/shop/product.html

index a9a7c808b3b8b65c8f6c57d3965a9a9c6c60ff69..b090d3c557ce9472e0f0fd6debf466d2147f59cd 100644 (file)
@@ -1,5 +1,5 @@
 from django.contrib import admin
-from cartridge.shop.models import Product, ProductVariation
+from cartridge.shop.models import Product, ProductImage, ProductVariation
 from cartridge.shop.admin import ProductAdmin, ProductImageAdmin, ProductVariationAdmin
 
 # Register your models here.
@@ -21,10 +21,14 @@ from .models import ConditionGrading
 class RecordInline(admin.StackedInline):
     model = Record
     extra = 0
+    max_num = 0
 
 class RecordProductAdmin(ProductAdmin):
     inlines = [ProductImageAdmin, ProductVariationAdmin, RecordInline]
 
+class RecordAdmin(admin.ModelAdmin):
+    search_fields = ["title", "artist__name", "label__name"]
+
 admin.site.unregister(Product)
 admin.site.register(Product, RecordProductAdmin)
 
@@ -39,6 +43,6 @@ admin.site.register(User)
 admin.site.register(Artist)
 admin.site.register(Label)
 admin.site.register(Country)
-admin.site.register(Record)
+admin.site.register(Record, RecordAdmin)
 admin.site.register(Podcast)
 admin.site.register(ConditionGrading)
index 77830efd30076c438997a77d4d8e186f82e96887..64676e03ab30f96a541c6a83dbed390442ce1a2d 100644 (file)
@@ -221,7 +221,7 @@ class Command(BaseCommand):
     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
@@ -246,8 +246,11 @@ class Command(BaseCommand):
         IMG_PATH = os.path.join('uploads/product')
         shop_list = rec_models.Shop.objects.all()
 
-
+        DOUBLONS_TO_SKIP = [2734, 1006, 1393]
+        
         for shop in shop_list:
+            if shop.id in DOUBLONS_TO_SKIP:
+                continue
             obj, created = rec_models.Record.objects.get_or_create(pk=shop.id)
 
             obj.title = parser.unescape(shop.titre)
diff --git a/diggersdigest/records/migrations/0007_record_image.py b/diggersdigest/records/migrations/0007_record_image.py
new file mode 100644 (file)
index 0000000..9e4c70d
--- /dev/null
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('shop', '0003_auto_20150906_1911'),
+        ('records', '0006_auto_20150907_0835'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='record',
+            name='image',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, verbose_name='Image', blank=True, to='shop.ProductImage', null=True),
+        ),
+    ]
diff --git a/diggersdigest/records/migrations/0008_auto_20150909_0818.py b/diggersdigest/records/migrations/0008_auto_20150909_0818.py
new file mode 100644 (file)
index 0000000..f74a927
--- /dev/null
@@ -0,0 +1,25 @@
+# -*- 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', '0007_record_image'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='record',
+            name='performers',
+            field=models.ManyToManyField(related_name='records_performers', verbose_name='performers', to='records.Artist', blank=True),
+        ),
+        migrations.AlterField(
+            model_name='record',
+            name='product',
+            field=models.OneToOneField(related_name='record', null=True, on_delete=django.db.models.deletion.SET_NULL, verbose_name='product', to='shop.Product'),
+        ),
+    ]
diff --git a/diggersdigest/records/migrations/0009_remove_record_image.py b/diggersdigest/records/migrations/0009_remove_record_image.py
new file mode 100644 (file)
index 0000000..3e8458c
--- /dev/null
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('records', '0008_auto_20150909_0818'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='record',
+            name='image',
+        ),
+    ]
index 17bff9bc936a30b8bd347441dd128bdd95d08317..b914089456d3ff266213c52784585641d742fd53 100644 (file)
@@ -13,7 +13,7 @@ from mezzanine.core.models import CONTENT_STATUS_DRAFT, CONTENT_STATUS_PUBLISHED
 from mezzanine.blog.models import BlogPost
 from mezzanine.utils.models import upload_to
 
-from cartridge.shop.models import Product, ProductVariation
+from cartridge.shop.models import Product
 
 
 # Auto-generated Django models with manage.py inspectdb on the old database
@@ -226,7 +226,7 @@ class Record(models.Model):
 
     title = models.CharField(max_length=128)
     artist = models.ForeignKey(Artist, verbose_name=_('artist'), related_name='records_artists', null=True, on_delete=models.SET_NULL)
-    performers = models.ManyToManyField(Artist, verbose_name=_('performers'), related_name='records_performers')
+    performers = models.ManyToManyField(Artist, verbose_name=_('performers'), related_name='records_performers', blank=True)
     record_status = models.IntegerField(_('record status'), choices=NOVELTY_CHOICES, default=NEW)
     label = models.ForeignKey(Label, verbose_name=_('label'), related_name='records', null=True, on_delete=models.SET_NULL)
     release_year = models.IntegerField(_('release year'), null=True, choices=YEAR_CHOICES)
@@ -237,7 +237,7 @@ class Record(models.Model):
     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)
+    product = models.OneToOneField(Product, verbose_name=_('product'), related_name='record', null=True, on_delete=models.SET_NULL)
     def __unicode__(self):
         return " - ".join([self.artist.name, self.title])
 
index 9a9cae427d076f04779e9113fabcfa55cf46d30b..3111148b35217cb2312bf0fe859e021e53bc1542 100644 (file)
@@ -24,7 +24,7 @@
             <h4>{{ category.title }}</h4>
         </div>
     </a>
-    </div>  
+    </div>
     {% endfor %}
 {% else %}
     {% for category in child_categories %}
index 4d4000251242661e963ac94ed694a2706a63d3de..344c55ee694f89c0841541d750b7420a738c4c55 100644 (file)
@@ -88,44 +88,48 @@ $(function () {
 
 
 <ul>
-  <li><strong>{{ product.records.first.artist }}</strong></li>
-  <li><em>{{ product.records.first.title }}</em></li>
+  <li><strong>{{ product.record.artist }}</strong></li>
+  <li><em>{{ product.record.title }}</em></li>
   <li>
     {% trans "Label:" %}
-    {{ product.records.first.label }}
+    {{ product.record.label }}
   </li>
   <li>
     {% trans "Country:" %}
-    {{ product.records.first.country }}
+    {{ product.record.country }}
    </li>
-  {% if product.records.first.release_year %}
+  {% if product.record.release_year %}
   <li>
     {% trans "Release year:" %}
-    {{ product.records.first.release_year }}
+    {{ product.record.release_year }}
   </li>
   {% else %}
   <li>
     {% trans "Release decade:" %}
-    {{ product.records.first.release_decade }}</li>
+    {{ product.record.release_decade }}</li>
   {% endif %}
   <li>
     {% trans "Cover:" %}
     <a class="badge" tabindex="0" role="button" data-toggle="popover" data-trigger="hover focus"
-      title="{{ product.records.first.cover_condition.name }}"
-    data-content="{{ product.records.first.cover_condition.description }}">
-    {{ product.records.first.cover_condition.abbr }}
+      title="{{ product.record.cover_condition.name }}"
+    data-content="{{ product.record.cover_condition.description }}">
+    {{ product.record.cover_condition.abbr }}
   </a>
   </li>
   <li>
     {% trans " Vinyl:" %}
     <a class="badge" tabindex="0" role="button" data-toggle="popover" data-trigger="hover focus"
-      title="{{ product.records.first.vinyl_condition.name }}"
-    data-content="{{ product.records.first.cover_condition.description }}">
-    {{ product.records.first.vinyl_condition.abbr }}
+      title="{{ product.record.vinyl_condition.name }}"
+    data-content="{{ product.record.cover_condition.description }}">
+    {{ product.record.vinyl_condition.abbr }}
   </a>
   </li>
 </ul>
-
+{% if product.record.audio_file %}
+<audio controls>
+    <source src="{{ MEDIA_URL }}{{ product.record.audio_file }}">
+</audio>
+{% endif %}
 
 {% editable product.content %}
 {{ product.content|richtext_filters|safe }}