How to Represent a Room as A Django Model

Task: To Represent a Room as a Django Model

Objectives:


At the end of these Section you should be able to :

  1.  Create a Django Model
  2. Assign attributes to the model
  3. Define operations for the model
  4. Mapping model attribute to the database fiels

Summary:


We cannot think properly of a room without considering its three dimensional properties, its representation in space and time, and as well as its behaviour. After Subclassing the django.db.model we have associated a desirable model to the class and perform some operations on the attributes. And as stated by the fundermental axion of the Object Oriented  principle every instance of the created model would have access to this operations.

Creating a Room Model


In creating a model we have to solve two problems:

  • Get the attribute of the model: The process of getting the attribute deals with thinking in terms of what specific data you want the application to hold
  • Decleare the behaviour of the model: Lets think of the model's behaviour in terms of the functions that is associated with our model.

The attribute of our model would be:

We have recognized our attributes to be:

  • Length
  • heigth
  • width
  • thickness: we would also consider the thickness of the lines
  • while the length and width of the roof for the from would be the same, the height of the room would be different.

The behaviour of our Model:

  • Create length, get length
  • create height, get heigth
  • create width, get width
  • create thickness, get thickness
  • set roofLength, see roofWidth
  • create roofHeigth, get roofHeigth

For the complete model check my GitHub gist:

<script src="https://gist.github.com/OkayJosh/f5b6fa2b596ea2b84598193d6e446751.js"></script>

Series-one Replies 0 Views 106 Users 0

Suggested Topics