Add docstring to Company app

This commit is contained in:
Oliver Walters 2019-04-27 20:43:27 +10:00
parent d9169a0dd1
commit c3f0570926
4 changed files with 43 additions and 3 deletions

View File

@ -1,7 +1,5 @@
""" """
Build models Build database model definitions
Defines the database models for part Builds
""" """
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-

View File

@ -1,3 +1,7 @@
"""
Provides a JSON API for the Company app
"""
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
@ -12,6 +16,13 @@ from .serializers import CompanySerializer
class CompanyList(generics.ListCreateAPIView): class CompanyList(generics.ListCreateAPIView):
""" API endpoint for accessing a list of Company objects
Provides two methods:
- GET: Return list of objects
- POST: Create a new Company object
"""
serializer_class = CompanySerializer serializer_class = CompanySerializer
queryset = Company.objects.all() queryset = Company.objects.all()
@ -44,6 +55,7 @@ class CompanyList(generics.ListCreateAPIView):
class CompanyDetail(generics.RetrieveUpdateDestroyAPIView): class CompanyDetail(generics.RetrieveUpdateDestroyAPIView):
""" API endpoint for detail of a single Company object """
queryset = Company.objects.all() queryset = Company.objects.all()
serializer_class = CompanySerializer serializer_class = CompanySerializer

View File

@ -1,3 +1,7 @@
"""
Django Forms for interacting with Company objects
"""
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
@ -7,6 +11,7 @@ from .models import Company
class EditCompanyForm(HelperForm): class EditCompanyForm(HelperForm):
""" Form for editing a Company object """
class Meta: class Meta:
model = Company model = Company
@ -26,6 +31,7 @@ class EditCompanyForm(HelperForm):
class CompanyImageForm(HelperForm): class CompanyImageForm(HelperForm):
""" Form for uploading a Company image """
class Meta: class Meta:
model = Company model = Company

View File

@ -1,3 +1,7 @@
"""
Company database model definitions
"""
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
@ -8,6 +12,16 @@ from django.urls import reverse
def rename_company_image(instance, filename): def rename_company_image(instance, filename):
""" Function to rename a company image after upload
Args:
instance: Company object
filename: uploaded image filename
Returns:
New image filename
"""
base = 'company_images' base = 'company_images'
if filename.count('.') > 0: if filename.count('.') > 0:
@ -24,6 +38,9 @@ def rename_company_image(instance, filename):
class Company(models.Model): class Company(models.Model):
""" A Company object represents an external company.
It may be a supplier or a customer (or both).
"""
name = models.CharField(max_length=100, unique=True, name = models.CharField(max_length=100, unique=True,
help_text='Company name') help_text='Company name')
@ -54,21 +71,28 @@ class Company(models.Model):
is_supplier = models.BooleanField(default=True) is_supplier = models.BooleanField(default=True)
def __str__(self): def __str__(self):
""" Get string representation of a Company """
return "{n} - {d}".format(n=self.name, d=self.description) return "{n} - {d}".format(n=self.name, d=self.description)
def get_absolute_url(self): def get_absolute_url(self):
""" Get the web URL for the detail view for this Company """
return reverse('company-detail', kwargs={'pk': self.id}) return reverse('company-detail', kwargs={'pk': self.id})
@property @property
def part_count(self): def part_count(self):
""" The number of parts supplied by this company """
return self.parts.count() return self.parts.count()
@property @property
def has_parts(self): def has_parts(self):
""" Return True if this company supplies any parts """
return self.part_count > 0 return self.part_count > 0
class Contact(models.Model): class Contact(models.Model):
""" A Contact represents a person who works at a particular company.
A Company may have zero or more associated Contact objects
"""
name = models.CharField(max_length=100) name = models.CharField(max_length=100)