show related movie based on imdb or serie title prefix
This commit is contained in:
parent
71c7ba84d0
commit
1acae4f155
2 changed files with 29 additions and 0 deletions
|
@ -8,6 +8,8 @@ from common.models import Entity, Mark, Review, Tag
|
|||
from common.utils import ChoicesDictGenerator, GenerateDateUUIDMediaFilePath
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
from django.db.models import Q
|
||||
import re
|
||||
|
||||
|
||||
def movie_cover_path(instance, filename):
|
||||
|
@ -181,6 +183,15 @@ class Movie(Entity):
|
|||
translated_genre.append(MovieGenreTranslator[g])
|
||||
return translated_genre
|
||||
|
||||
def get_related_movies(self):
|
||||
imdb = 'no match' if self.imdb_code is None or self.imdb_code == '' else self.imdb_code
|
||||
qs = Q(imdb_code=imdb)
|
||||
if self.is_series:
|
||||
prefix = re.sub(r'\d+', '', re.sub(r'\s+第.+季', '', self.title))
|
||||
qs = qs | Q(title__startswith=prefix)
|
||||
qs = qs & ~Q(id=self.id)
|
||||
return Movie.objects.filter(qs).order_by('season')
|
||||
|
||||
@property
|
||||
def verbose_category_name(self):
|
||||
if self.is_series:
|
||||
|
|
|
@ -395,6 +395,24 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if movie.get_related_movies.count > 0 %}
|
||||
<div class="aside-section-wrapper">
|
||||
<div class="action-panel">
|
||||
<div class="action-panel__label">{% trans '相关条目' %}</div>
|
||||
<div >
|
||||
{% for m in movie.get_related_movies %}
|
||||
<p>
|
||||
<a href="{% url 'movies:retrieve' m.id %}">{{ m.title }}</a>
|
||||
{% if movie.source_site != m.source_site %}
|
||||
<span class="source-label source-label__{{ m.source_site }}">{{ m.get_source_site_display }}</span>
|
||||
{% endif %}
|
||||
</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
|
Loading…
Add table
Reference in a new issue