Reverse lookup for company URL

- Added some simple tests
This commit is contained in:
Oliver Walters 2019-04-24 23:55:11 +10:00
parent 5098712d9c
commit a2d4403968
2 changed files with 20 additions and 3 deletions

View File

@ -4,6 +4,7 @@ from __future__ import unicode_literals
import os
from django.db import models
from django.urls import reverse
def rename_company_image(instance, filename):
@ -56,7 +57,7 @@ class Company(models.Model):
return "{n} - {d}".format(n=self.name, d=self.description)
def get_absolute_url(self):
return "/company/{id}/".format(id=self.id)
return reverse('company-detail', kwargs={'pk': self.id})
@property
def part_count(self):

View File

@ -1,3 +1,19 @@
# from django.test import TestCase
from django.test import TestCase
# Create your tests here.
from .models import Company
class CompanySimpleTest(TestCase):
def setUp(self):
Company.objects.create(name='ABC Co.',
description='Seller of ABC products',
website='www.abc-sales.com',
address='123 Sales St.',
is_customer=False,
is_supplier=True)
def test_company_model(self):
c = Company.objects.get(pk=1)
self.assertEqual(c.name, 'ABC Co.')
self.assertEqual(c.get_absolute_url(), '/company/1/')