Skip to content
This repository has been archived by the owner on Apr 21, 2019. It is now read-only.

Commit

Permalink
Remove role field from Roles model.
Browse files Browse the repository at this point in the history
* Update comicimporter & releated_creator template for the change.
* Unable to remove dependency on multiselectfield since the initial migration depends on it. Ughh.
  • Loading branch information
bpepple committed Jan 20, 2018
1 parent dfa5159 commit a91009c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
17 changes: 17 additions & 0 deletions comics/migrations/0007_remove_roles_roles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.0.1 on 2018-01-20 20:39

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('comics', '0006_roles_migrate_data'),
]

operations = [
migrations.RemoveField(
model_name='roles',
name='roles',
),
]
17 changes: 0 additions & 17 deletions comics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from django.core.validators import RegexValidator
from django.db import models
from multiselectfield import MultiSelectField
from solo.models import SingletonModel


Expand All @@ -16,21 +15,6 @@
(2, 'Read'),
)

# Creator roles for an issue
ROLE_CHOICES = (
('artist', 'Artist'),
('colorist', 'Colorist'),
('cover', 'Cover'),
('editor', 'Editor'),
('inker', 'Inker'),
('journalist', 'Journalist'),
('letterer', 'Letterer'),
('other', 'Other'),
('penciler', 'Penciler'),
('production', 'Production'),
('writer', 'Writer'),
)


class Settings(SingletonModel):
help_str = ('A 40-character key provided by ComicVine. '
Expand Down Expand Up @@ -246,7 +230,6 @@ def __str__(self):
class Roles(models.Model):
creator = models.ForeignKey(Creator, on_delete=models.CASCADE)
issue = models.ForeignKey(Issue, on_delete=models.CASCADE)
roles = MultiSelectField(choices=ROLE_CHOICES)
role = models.ManyToManyField(Role)

def __str__(self):
Expand Down
7 changes: 6 additions & 1 deletion comics/templates/comics/related_creators.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ <h2>Creators</h2>
</div>
</a>
<a href="{% url 'creator:detail' roles.creator.slug %}"><p>{{ roles.creator.name }}</p></a>
<p><small><em>{{ roles.roles }}</em></small></p>
<p>
{% for r in roles.role.all %}
{% if not forloop.first %}, {% endif %}
<small><em>{{ r.name }}</em></small>
{% endfor %}
</p>
</li>
{% endfor %}
</ul>
Expand Down
15 changes: 11 additions & 4 deletions comics/utils/comicimporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import requests_cache

from comics.models import (Arc, Character, Creator, Issue,
Publisher, Roles, Series, Team, Settings)
Publisher, Role, Roles, Series,
Team, Settings)

from . import utils
from .comicapi.comicarchive import MetaDataStyle, ComicArchive
Expand Down Expand Up @@ -588,9 +589,15 @@ def addComicFromMetadata(self, md):
creator_obj, c_create = Creator.objects.get_or_create(
cvid=p['id'],)

Roles.objects.create(creator=creator_obj,
issue=issue_obj,
roles=re.sub(' ', '', p['role']))
role_obj = Roles.objects.create(
creator=creator_obj, issue=issue_obj)

roles = p['role'].split(',')
for role in roles:
# Remove any whitespace
role = role.strip()
r, r_create = Role.objects.get_or_create(name=role.title())
role_obj.role.add(r)

if c_create:
new_slug = orig = slugify(p['name'])
Expand Down

0 comments on commit a91009c

Please sign in to comment.