mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Reverse url lookup for Part model
This commit is contained in:
parent
f9db3b680d
commit
0bc5617825
@ -89,7 +89,7 @@ class Part(models.Model):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return '/part/{id}/'.format(id=self.id)
|
return reverse('part-detail', kwargs={'pk': self.id})
|
||||||
|
|
||||||
# Short name of the part
|
# Short name of the part
|
||||||
name = models.CharField(max_length=100, unique=True, help_text='Part name (must be unique)')
|
name = models.CharField(max_length=100, unique=True, help_text='Part name (must be unique)')
|
||||||
|
22
InvenTree/part/test_part.py
Normal file
22
InvenTree/part/test_part.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from .models import Part, PartCategory
|
||||||
|
|
||||||
|
class SimplePartTest(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
|
||||||
|
cat = PartCategory.objects.create(name='TLC', description='Top level category')
|
||||||
|
|
||||||
|
self.px = Part.objects.create(name='x', description='A part called x', buildable=True)
|
||||||
|
self.py = Part.objects.create(name='y', description='A part called y', consumable=False)
|
||||||
|
self.pz = Part.objects.create(name='z', description='A part called z', category=cat)
|
||||||
|
|
||||||
|
def test_metadata(self):
|
||||||
|
self.assertEqual(self.px.name, 'x')
|
||||||
|
self.assertEqual(self.py.get_absolute_url(), '/part/2/')
|
||||||
|
self.assertEqual(str(self.pz), 'z - A part called z')
|
||||||
|
|
||||||
|
def test_category(self):
|
||||||
|
self.assertEqual(self.px.category_path, '')
|
||||||
|
self.assertEqual(self.pz.category_path, 'TLC')
|
@ -1,3 +0,0 @@
|
|||||||
# from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
Loading…
Reference in New Issue
Block a user