mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add docstring to Company app
This commit is contained in:
parent
d9169a0dd1
commit
c3f0570926
@ -1,7 +1,5 @@
|
||||
"""
|
||||
Build models
|
||||
|
||||
Defines the database models for part Builds
|
||||
Build database model definitions
|
||||
"""
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
@ -1,3 +1,7 @@
|
||||
"""
|
||||
Provides a JSON API for the Company app
|
||||
"""
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
@ -12,6 +16,13 @@ from .serializers import CompanySerializer
|
||||
|
||||
|
||||
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
|
||||
queryset = Company.objects.all()
|
||||
@ -44,6 +55,7 @@ class CompanyList(generics.ListCreateAPIView):
|
||||
|
||||
|
||||
class CompanyDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
""" API endpoint for detail of a single Company object """
|
||||
|
||||
queryset = Company.objects.all()
|
||||
serializer_class = CompanySerializer
|
||||
|
@ -1,3 +1,7 @@
|
||||
"""
|
||||
Django Forms for interacting with Company objects
|
||||
"""
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
@ -7,6 +11,7 @@ from .models import Company
|
||||
|
||||
|
||||
class EditCompanyForm(HelperForm):
|
||||
""" Form for editing a Company object """
|
||||
|
||||
class Meta:
|
||||
model = Company
|
||||
@ -26,6 +31,7 @@ class EditCompanyForm(HelperForm):
|
||||
|
||||
|
||||
class CompanyImageForm(HelperForm):
|
||||
""" Form for uploading a Company image """
|
||||
|
||||
class Meta:
|
||||
model = Company
|
||||
|
@ -1,3 +1,7 @@
|
||||
"""
|
||||
Company database model definitions
|
||||
"""
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
@ -8,6 +12,16 @@ from django.urls import reverse
|
||||
|
||||
|
||||
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'
|
||||
|
||||
if filename.count('.') > 0:
|
||||
@ -24,6 +38,9 @@ def rename_company_image(instance, filename):
|
||||
|
||||
|
||||
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,
|
||||
help_text='Company name')
|
||||
@ -54,21 +71,28 @@ class Company(models.Model):
|
||||
is_supplier = models.BooleanField(default=True)
|
||||
|
||||
def __str__(self):
|
||||
""" Get string representation of a Company """
|
||||
return "{n} - {d}".format(n=self.name, d=self.description)
|
||||
|
||||
def get_absolute_url(self):
|
||||
""" Get the web URL for the detail view for this Company """
|
||||
return reverse('company-detail', kwargs={'pk': self.id})
|
||||
|
||||
@property
|
||||
def part_count(self):
|
||||
""" The number of parts supplied by this company """
|
||||
return self.parts.count()
|
||||
|
||||
@property
|
||||
def has_parts(self):
|
||||
""" Return True if this company supplies any parts """
|
||||
return self.part_count > 0
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user