2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-13 08:21:26 +00:00

Include part image URL in Part API

This commit is contained in:
Oliver Walters
2019-05-08 15:25:28 +10:00
parent 6a04e8b059
commit 416b5c9820
2 changed files with 14 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import tablib
from django.utils.translation import gettext_lazy as _
from django.core.exceptions import ValidationError
from django.urls import reverse
from django.conf import settings
from django.db import models
from django.core.validators import MinValueValidator
@ -120,8 +121,17 @@ class Part(models.Model):
"""
def get_absolute_url(self):
""" Return the web URL for viewing this part """
return reverse('part-detail', kwargs={'pk': self.id})
def get_image_url(self):
""" Return the URL of the image for this part """
if self.image:
return os.path.join(settings.MEDIA_URL, str(self.image.url))
else:
return ''
# Short name of the part
name = models.CharField(max_length=100, unique=True, blank=False, help_text='Part name (must be unique)')