Skip to content

Models

Administration

SingletonModel

A Singleton model that ensures there is only one instance of this model that can not be deleted.

Source code in backend/administration/models.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class SingletonModel(models.Model):
    """
    A Singleton model that ensures there is only one instance
    of this model that can not be deleted.

    """

    class Meta:
        abstract = True

    def save(self, *args, **kwargs):
        """
        Overrides save for model to ensure there is only ever 1 instance.

        Raises:
            ValidationError (String): Raises an error if there is already an instance
                of this model.

        Returns:
            self (Model): Returns itself on save.
        """
        if not self.pk and self.__class__.objects.exists():
            raise ValidationError("There is already one instance of this model")
        return super(SingletonModel, self).save(*args, **kwargs)

    def delete(self, *args, **kwargs):
        """
        Overrides delete, not allowing deletions.

        Raises:
            ValidationError (String): On deletion attemp, returns an error not allowing
                deletions.
        """
        raise ValidationError("You cannot delete this object")

save(*args, **kwargs)

Overrides save for model to ensure there is only ever 1 instance.

Raises:

Type Description
ValidationError(String)

Raises an error if there is already an instance of this model.

Returns:

Name Type Description
self Model

Returns itself on save.

Source code in backend/administration/models.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def save(self, *args, **kwargs):
    """
    Overrides save for model to ensure there is only ever 1 instance.

    Raises:
        ValidationError (String): Raises an error if there is already an instance
            of this model.

    Returns:
        self (Model): Returns itself on save.
    """
    if not self.pk and self.__class__.objects.exists():
        raise ValidationError("There is already one instance of this model")
    return super(SingletonModel, self).save(*args, **kwargs)

delete(*args, **kwargs)

Overrides delete, not allowing deletions.

Raises:

Type Description
ValidationError(String)

On deletion attemp, returns an error not allowing deletions.

Source code in backend/administration/models.py
31
32
33
34
35
36
37
38
39
def delete(self, *args, **kwargs):
    """
    Overrides delete, not allowing deletions.

    Raises:
        ValidationError (String): On deletion attemp, returns an error not allowing
            deletions.
    """
    raise ValidationError("You cannot delete this object")

Version

Model representing app version.

Attributes:

Name Type Description
version_number CharField

The current version of the app. Required.

Source code in backend/administration/models.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class Version(SingletonModel):
    """
    Model representing app version.

    Attributes:
        version_number (CharField): The current version of the app. Required.
    """

    version_number = models.CharField(max_length=10)

    def __str__(self):
        """
        Returns:
            (String): The version number of the app.
        """
        return self.version_number

__str__()

Returns:

Type Description
String

The version number of the app.

Source code in backend/administration/models.py
52
53
54
55
56
57
def __str__(self):
    """
    Returns:
        (String): The version number of the app.
    """
    return self.version_number

Material

Material

Model representing a material.

Attributes:

Name Type Description
material_object MaterialObject

A reference to a Material Object. Required.

quantity IntegerField

The quantity of material objects. Required.

material_status Optional[ForeignKey]

A reference to a Material Status. Defaults to None.

project Optional[ForeignKey]

A refrence to a Project. Defaults to None.

Source code in backend/material/models.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
class Material(models.Model):
    """
    Model representing a material.

    Attributes:
        material_object (MaterialObject): A reference to a Material Object. Required.
        quantity (IntegerField): The quantity of material objects. Required.
        material_status (Optional[ForeignKey]): A reference to a Material Status.
            Defaults to None.
        project (Optional[ForeignKey]): A refrence to a Project. Defaults to None.
    """

    material_object = models.ForeignKey(
        MaterialObject, on_delete=models.CASCADE
    )
    quantity = models.IntegerField(default=1)
    material_status = models.ForeignKey(
        MaterialStatus,
        null=True,
        on_delete=models.SET_NULL,
        blank=True,
        default=None,
    )
    project = models.ForeignKey(
        Project, on_delete=models.CASCADE, null=True, blank=True, default=None
    )

    def __str__(self):
        """
        Returns:
            (String): The Material Object Name
        """
        return self.material_object.material_object_name

__str__()

Returns:

Type Description
String

The Material Object Name

Source code in backend/material/models.py
172
173
174
175
176
177
def __str__(self):
    """
    Returns:
        (String): The Material Object Name
    """
    return self.material_object.material_object_name

MaterialObject

Model representing a material object.

Attributes:

Name Type Description
material_object_name CharField

The name of a material object. Required.

thickness_in Optional[DecimalField]

The thickness of the object. Defaults to None.

width_in Optional[DecimalField]

The width of the object. Defaults to None.

length_in Optional[DecimalField]

The length of the object. Defaults to None.

wood_species Optional[ForeignKey]

A refernce to a Wood Species object. Defaults to None.

store Optional[ForeignKey]

A refrence to a Store. Defaults to None.

store_aisle Optional[CharField]

The aisle of Store this material object can be

store_bin Optional[CharField]

The bin of the aisle. Defaults to None.

store_price Optional[DecimalField]

The price of this material object. Defaults to 0.00.

material_object_full_name CharField

The full name of the object. Unique. Defaults to None. Limit 512. On save, set to dimensions + wood species name + material_object_name

Source code in backend/material/models.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
class MaterialObject(models.Model):
    """
    Model representing a material object.

    Attributes:
        material_object_name (CharField): The name of a material object. Required.
        thickness_in (Optional[DecimalField]): The thickness of the object. Defaults to None.
        width_in (Optional[DecimalField]): The width of the object. Defaults to None.
        length_in (Optional[DecimalField]): The length of the object. Defaults to None.
        wood_species (Optional[ForeignKey]): A refernce to a Wood Species object. Defaults to None.
        store (Optional[ForeignKey]): A refrence to a Store. Defaults to None.
        store_aisle (Optional[CharField]): The aisle of Store this material object can be
        found. Defaults to None.
        store_bin (Optional[CharField]): The bin of the aisle. Defaults to None.
        store_price (Optional[DecimalField]): The price of this material object. Defaults to 0.00.
        material_object_full_name (CharField): The full name of the object. Unique. Defaults to None.
            Limit 512. On save, set to dimensions + wood species name + material_object_name
    """

    material_object_name = models.CharField(max_length=254)
    thickness_in = models.DecimalField(
        max_digits=10, decimal_places=5, null=True, blank=True, default=None
    )
    width_in = models.DecimalField(
        max_digits=10, decimal_places=5, null=True, blank=True, default=None
    )
    length_in = models.DecimalField(
        max_digits=10, decimal_places=5, null=True, blank=True, default=None
    )
    wood_species = models.ForeignKey(
        WoodSpecies,
        null=True,
        on_delete=models.SET_NULL,
        blank=True,
        default=None,
    )
    store = models.ForeignKey(
        Store, null=True, on_delete=models.SET_NULL, blank=True, default=None
    )
    store_aisle = models.CharField(
        max_length=254, null=True, blank=True, default=None
    )
    store_bin = models.CharField(
        max_length=254, null=True, blank=True, default=None
    )
    store_price = models.DecimalField(
        max_digits=12, decimal_places=2, default=0.00, blank=True, null=True
    )
    material_object_full_name = models.CharField(
        max_length=512, unique=True, null=True, blank=True, default=None
    )

    def save(self, *args, **kwargs):
        """
        Override save method to compute material_full_name before saving.
        """
        dimensions = "x".join(
            str(value)
            for value in [self.thickness_in, self.width_in, self.length_in]
            if value is not None
        )
        wood_species_name = (
            self.wood_species.wood_species_name if self.wood_species else ""
        )
        components = filter(
            None, [dimensions, wood_species_name, self.material_object_name]
        )
        self.material_object_full_name = " ".join(components)
        super().save(*args, **kwargs)

    def __str__(self):
        """
        Returns:
            (String): The Material Object Name
        """
        return self.material_object_full_name

save(*args, **kwargs)

Override save method to compute material_full_name before saving.

Source code in backend/material/models.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def save(self, *args, **kwargs):
    """
    Override save method to compute material_full_name before saving.
    """
    dimensions = "x".join(
        str(value)
        for value in [self.thickness_in, self.width_in, self.length_in]
        if value is not None
    )
    wood_species_name = (
        self.wood_species.wood_species_name if self.wood_species else ""
    )
    components = filter(
        None, [dimensions, wood_species_name, self.material_object_name]
    )
    self.material_object_full_name = " ".join(components)
    super().save(*args, **kwargs)

__str__()

Returns:

Type Description
String

The Material Object Name

Source code in backend/material/models.py
137
138
139
140
141
142
def __str__(self):
    """
    Returns:
        (String): The Material Object Name
    """
    return self.material_object_full_name

MaterialStatus

Model representing a status for materials.

Attributes:

Name Type Description
material_status CharField

The text status of a material. Required.

Source code in backend/material/models.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class MaterialStatus(models.Model):
    """
    Model representing a status for materials.

    Attributes:
        material_status (CharField): The text status of a material. Required.
    """

    material_status = models.CharField(max_length=254, unique=True)

    class Meta:
        verbose_name_plural = "Material statuses"

    def __str__(self):
        """
        Returns:
            (String): The Material Status
        """
        return self.material_status

__str__()

Returns:

Type Description
String

The Material Status

Source code in backend/material/models.py
20
21
22
23
24
25
def __str__(self):
    """
    Returns:
        (String): The Material Status
    """
    return self.material_status

Store

Model representing a store

Attributes:

Name Type Description
store_name CharField

The name of a store. Required. Unique.

Source code in backend/material/models.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Store(models.Model):
    """
    Model representing a store

    Attributes:
        store_name (CharField): The name of a store. Required. Unique.
    """

    store_name = models.CharField(max_length=254, unique=True)

    def __str__(self):
        """
        Returns:
            (String): The Store Name
        """
        return self.store_name

__str__()

Returns:

Type Description
String

The Store Name

Source code in backend/material/models.py
59
60
61
62
63
64
def __str__(self):
    """
    Returns:
        (String): The Store Name
    """
    return self.store_name

WoodSpecies

Model representing a wood species for materials.

Attributes:

Name Type Description
wood_species_name CharField

The name of a species of wood. Required.

Source code in backend/material/models.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class WoodSpecies(models.Model):
    """
    Model representing a wood species for materials.

    Attributes:
        wood_species_name (CharField): The name of a species of wood. Required.
    """

    wood_species_name = models.CharField(max_length=254, unique=True)

    class Meta:
        verbose_name_plural = "Wood species"

    def __str__(self):
        """
        Returns:
            (String): The Wood Species Name
        """
        return self.wood_species_name

__str__()

Returns:

Type Description
String

The Wood Species Name

Source code in backend/material/models.py
41
42
43
44
45
46
def __str__(self):
    """
    Returns:
        (String): The Wood Species Name
    """
    return self.wood_species_name

Note

attachment_name(instance, filename)

Takes a file instance and returns the attachment path with the file name.

Parameters:

Name Type Description Default
instance
required
filename String

The name of the file

required

Returns:

Type Description
String

The path to attachments with the filename

Source code in backend/note/models.py
11
12
13
14
15
16
17
18
19
20
21
22
23
def attachment_name(instance, filename):
    """
    Takes a file instance and returns the attachment path with
    the file name.

    Args:
        instance ():
        filename (String): The name of the file

    Returns:
        (String): The path to attachments with the filename
    """
    return f"attachments/{filename}"

Note

Model representing a note.

Attributes:

Name Type Description
note_date DateField

The date of the note. Required.

note CharField

The text of the note. Required.

attachment Optional[FileField]

Any attachment associated with this note. Dafaults to None.

project Optional[ForeignKey]

A reference to a Project. Defaults to None.

Source code in backend/note/models.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Note(models.Model):
    """
    Model representing a note.

    Attributes:
        note_date (DateField): The date of the note. Required.
        note (CharField): The text of the note. Required.
        attachment (Optional[FileField]): Any attachment associated with this
            note. Dafaults to None.
        project (Optional[ForeignKey]): A reference to a Project. Defaults to
            None.
    """

    note_date = models.DateField(default=current_date)
    note = models.CharField(max_length=508)
    attachment = models.FileField(
        upload_to=attachment_name, null=True, blank=True, default=None
    )
    project = models.ForeignKey(
        Project, on_delete=models.CASCADE, null=True, blank=True, default=None
    )

    def __str__(self):
        """
        Returns:
            (String): The Note Date
        """
        return self.note_date.strftime("%Y-%m-%d")

__str__()

Returns:

Type Description
String

The Note Date

Source code in backend/note/models.py
48
49
50
51
52
53
def __str__(self):
    """
    Returns:
        (String): The Note Date
    """
    return self.note_date.strftime("%Y-%m-%d")

Part

Part

Model representing a part.

Attributes:

Name Type Description
quantity IntegerField

The quantity of this part. Required.

part_name CharField

The name of the part. Required. 254 limit.

part_status PartStatus

A reference to a Part Status. Required.

rough_thickness_in DecimalField

The rough thickness of the part in inches. Required.

rough_width_in DecimalField

The rough width of the part in inches. Required.

rough_length_in DecimalField

The rough length of the part in inches. Required.

finished_thickness_in DecimalField

The finished thickness of the part in inches. Required.

finished_width_in DecimalField

The finished width of the part in inches. Required.

finished_length_in DecimalField

The finished length of the part in inches. Required.

project Project

A referece to a Project. Required.

Source code in backend/part/models.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class Part(models.Model):
    """

    Model representing a part.

    Attributes:
        quantity (IntegerField): The quantity of this part. Required.
        part_name (CharField): The name of the part. Required. 254 limit.
        part_status (PartStatus): A reference to a Part Status. Required.
        rough_thickness_in (DecimalField): The rough thickness of the part in inches.
            Required.
        rough_width_in (DecimalField): The rough width of the part in inches. Required.
        rough_length_in (DecimalField): The rough length of the part in inches. Required.
        finished_thickness_in (DecimalField): The finished thickness of the part in inches.
            Required.
        finished_width_in (DecimalField): The finished width of the part in inches. Required.
        finished_length_in (DecimalField): The finished length of the part in inches. Required.
        project (Project): A referece to a Project. Required.

    """

    quantity = models.IntegerField()
    part_name = models.CharField(max_length=254)
    part_status = models.ForeignKey(
        PartStatus, null=True, on_delete=models.SET_NULL
    )
    rough_thickness_in = models.DecimalField(max_digits=10, decimal_places=5)
    rough_width_in = models.DecimalField(max_digits=10, decimal_places=5)
    rough_length_in = models.DecimalField(max_digits=10, decimal_places=5)
    finished_thickness_in = models.DecimalField(max_digits=10, decimal_places=5)
    finished_width_in = models.DecimalField(max_digits=10, decimal_places=5)
    finished_length_in = models.DecimalField(max_digits=10, decimal_places=5)
    project = models.ForeignKey(
        Project, null=True, on_delete=models.SET_NULL, blank=True, default=None
    )

    def __str__(self):
        return self.part_name

__str__()

Source code in backend/part/models.py
62
63
def __str__(self):
    return self.part_name

PartStatus

Model representing a status for parts.

Attributes:

Name Type Description
part_status CharField

The text status of a part. Required.

Source code in backend/part/models.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class PartStatus(models.Model):
    """

    Model representing a status for parts.

    Attributes:
        part_status (CharField): The text status of a part. Required.

    """

    part_status = models.CharField(max_length=254, unique=True)

    class Meta:
        verbose_name_plural = "Part statuses"

    def __str__(self):
        return self.part_status

__str__()

Source code in backend/part/models.py
22
23
def __str__(self):
    return self.part_status

Project

Project

Model representing a project.

Attributes:

Name Type Description
project_name CharField

The name of the poject. Required. Unique. 254 limit.

project_status ProjectStatus

A reference to a Project Status. Required.

project_image Optional[FileField]

An image for the project. Defaults to None.

start_date Optional[DateField]

The date this project started. Defaults to None.

due_date Optional[DateField]

The date this project is due. Defaults to None.

completed_date Optioanl[DateField]

The date this project completed. Defaults to None.

depth_in Optional[DecimalField]

The depth in inches. Defaults to 0.

width_in Optional[DecimalField]

The width in inches. Defaults to 0.

height_in Optional[DecimalField]

The height in inches. Defaults to 0.

Source code in backend/project/models.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Project(models.Model):
    """

    Model representing a project.

    Attributes:
        project_name (CharField): The name of the poject. Required. Unique. 254 limit.
        project_status (ProjectStatus): A reference to a Project Status. Required.
        project_image (Optional[FileField]): An image for the project. Defaults to None.
        start_date (Optional[DateField]): The date this project started. Defaults to None.
        due_date (Optional[DateField]): The date this project is due. Defaults to None.
        completed_date (Optioanl[DateField]): The date this project completed. Defaults to None.
        depth_in (Optional[DecimalField]): The depth in inches. Defaults to 0.
        width_in (Optional[DecimalField]): The width in inches. Defaults to 0.
        height_in (Optional[DecimalField]): The height in inches. Defaults to 0.

    """

    project_name = models.CharField(max_length=254, unique=True)
    project_status = models.ForeignKey(
        ProjectStatus, null=True, on_delete=models.SET_NULL
    )
    project_image = models.FileField(
        upload_to=image_name, default=None, null=True, blank=True
    )
    start_date = models.DateField(null=True, blank=True, default=None)
    due_date = models.DateField(null=True, blank=True, default=None)
    completed_date = models.DateField(null=True, blank=True, default=None)
    depth_in = models.DecimalField(
        max_digits=10, decimal_places=5, null=True, blank=True, default=0
    )
    width_in = models.DecimalField(
        max_digits=10, decimal_places=5, null=True, blank=True, default=0
    )
    height_in = models.DecimalField(
        max_digits=10, decimal_places=5, null=True, blank=True, default=0
    )

    def __str__(self):
        return self.project_name

__str__()

Source code in backend/project/models.py
66
67
def __str__(self):
    return self.project_name

ProjectPhase

Model representing a phase for projects.

Attributes:

Name Type Description
project_phase CharField

The text phase of a project. Required. Unique.

Source code in backend/project/models.py
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class ProjectPhase(models.Model):
    """

    Model representing a phase for projects.

    Attributes:
        project_phase (CharField): The text phase of a project. Required. Unique.

    """

    project_phase = models.CharField(max_length=254, unique=True)

    def __str__(self):
        return self.project_phase

__str__()

Source code in backend/project/models.py
82
83
def __str__(self):
    return self.project_phase

ProjectStatus

Model representing a status for projects.

Attributes:

Name Type Description
project_status CharField

The text status of a project. Required. Unique.

Source code in backend/project/models.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class ProjectStatus(models.Model):
    """

    Model representing a status for projects.

    Attributes:
        project_status (CharField): The text status of a project. Required.  Unique.

    """

    project_status = models.CharField(max_length=254, unique=True)

    class Meta:
        verbose_name_plural = "Project statuses"

    def __str__(self):
        return self.project_status

__str__()

Source code in backend/project/models.py
24
25
def __str__(self):
    return self.project_status

Task

Task

Model representing a task.

Attributes:

Name Type Description
task_name CharField

The name of the task. Required. Unique. 254 limit.

task_status TaskStatus

A reference to a Task Status. Required.

start_date Optional[DateField]

The date this task started. Defaults to None.

due_date Optional[DateField]

The date this task is due. Defaults to None.

completed_date Optional[DateField]

The date this task completed. Defaults to None.

project Optional[Project]

A referece to a Project. Defaults to None.

phase Optional[ProjectPhase]

A reference to a Project Phase. Defaults to None.

step Optional[IntegerField]

The number representing the order of the step. Defaults to None.

part Optioanl[Part]

A reference to a Part. Defaults to None.

Source code in backend/task/models.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class Task(models.Model):
    """

    Model representing a task.

    Attributes:
        task_name (CharField): The name of the task. Required. Unique. 254 limit.
        task_status (TaskStatus): A reference to a Task Status. Required.
        start_date (Optional[DateField]): The date this task started. Defaults to None.
        due_date (Optional[DateField]): The date this task is due. Defaults to None.
        completed_date (Optional[DateField]): The date this task completed. Defaults to None.
        project (Optional[Project]): A referece to a Project. Defaults to None.
        phase (Optional[ProjectPhase]): A reference to a Project Phase. Defaults to None.
        step (Optional[IntegerField]): The number representing the order of the step. Defaults to None.
        part (Optioanl[Part]): A reference to a Part. Defaults to None.

    """

    task_name = models.CharField(max_length=254, unique=True)
    task_status = models.ForeignKey(
        TaskStatus, null=True, on_delete=models.SET_NULL
    )
    start_date = models.DateField(null=True, blank=True, default=None)
    due_date = models.DateField(null=True, blank=True, default=None)
    completed_date = models.DateField(null=True, blank=True, default=None)
    project = models.ForeignKey(
        Project, null=True, on_delete=models.SET_NULL, blank=True, default=None
    )
    phase = models.ForeignKey(
        ProjectPhase,
        null=True,
        on_delete=models.SET_NULL,
        blank=True,
        default=None,
    )
    step = models.IntegerField(blank=True, null=True, default=None)
    part = models.ForeignKey(
        Part, null=True, on_delete=models.SET_NULL, blank=True, default=None
    )

    def __str__(self):
        return self.task_name

__str__()

Source code in backend/task/models.py
67
68
def __str__(self):
    return self.task_name

TaskStatus

Model representing a status for projects.

Attributes:

Name Type Description
task_status CharField

The text status of a task. Required.

Source code in backend/task/models.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class TaskStatus(models.Model):
    """

    Model representing a status for projects.

    Attributes:
        task_status (CharField): The text status of a task. Required.

    """

    task_status = models.CharField(max_length=254, unique=True)

    class Meta:
        verbose_name_plural = "Task statuses"

    def __str__(self):
        return self.task_status

__str__()

Source code in backend/task/models.py
23
24
def __str__(self):
    return self.task_status