I am creating a BOM App to generate a PDF file for Bill of Materials for our IT Network Department. I need help with database structure and foreign key to establish ORM. Based on these model I have created form which will take input from IT users and calculate the BOM for that instance using below models click here . Here we could have different vendors with each vendor has different device models types which includes parts/items which should tie into each other to utilize DRY principles and ORM mappings etc. Any basic layout should definitely help in this regards.
Any ideas would be a great start for me as I am Network Architect and don't have lot of experience into programming world just started getting into python coding and learning django.
class CiscoModel(models.Model):
router_switch_type = models.CharField(max_length=50)
def __str__(self):
return self.router_switch_type
class CiscoParts(models.Model):
model = models.ForeignKey(CiscoModel, on_delete=None)
part_number = models.CharField(max_length=50)
voice = models.BooleanField(default=False)
desc = models.CharField(max_length=200)
service_duration = models.IntegerField(blank=True, null=True)
unit_list_price = models.FloatField()
qty = models.IntegerField()
unit_net_price = models.FloatField(blank=True, null=True)
discount = models.IntegerField(blank=True, null=True)
extended_net_price = models.FloatField()
def __str__(self):
return self.part_number
class RuckusModel(models.Model):
switch_type = models.CharField(max_length=50)
def __str__(self):
return self.switch_type
class RuckusParts(models.Model):
model = models.ForeignKey(RuckusModel, on_delete=None)
sku = models.CharField(max_length=50)
desc = models.CharField(max_length=200)
service_duration = models.IntegerField()
unit_list_price = models.FloatField()
qty = models.IntegerField()
unit_net_price = models.FloatField()
discount = models.IntegerField()
extended_net_price = models.FloatField()
For Starters Identify Your Business Actors. Each Business Actor will be a class
Eg:
Device (Physical Device Unit)
DeviceModel (Product form a vendor)
DevicePart (Parts form a vendor)
Vendor (Indevidual Vendor)
DeviceModel Can have multiple 0 to Multiple Parts and 1 Part can belong to multiple DeviceModels so establish a Many to many relationships between DeviceModel and DevicePart M2M In Django
Then Vendor can Table which will have Foreign Key Relation with DeviceModel and DevicePart Table Both So That you will be able to identify who is the supplier for individual DeviceModel and DevicePart
Last You Device Table Will have a property related to an individual device like serial_number, owner, price, alongside a foreign key reference to DeviceModel
You can derive Inventory Reports as DB Views
class DeviceModel(models.Model):
device_model = models.CharField(max_length=50)
class Device(models.Model):
device_model = models.ForeignKey(DeviceModel, on_delete=None)
sku = models.CharField(max_length=50)
desc = models.CharField(max_length=200)
service_duration = models.IntegerField()
unit_list_price = models.FloatField()
unit_net_price = models.FloatField()
discount = models.IntegerField()
extended_net_price = models.FloatField()
class DevicePart(models.Model):
device_model = models.ManyToManyField(DeviceModel)
part_number = models.CharField(max_length=50, blank=True, null=True)
part_description = models.CharField(max_length=200, blank=True, null=True)
def __str__(self):
return self.device_model
class Vendor(models.Model):
ARISTA = 'Arista'
CISCO = 'Cisco'
RUCKUS = 'Ruckus'
VENDOR_CHOICES = [
(ARISTA, 'arista'),
(CISCO, 'cisco'),
(RUCKUS, 'ruckus'),
]
vendor = models.CharField(
max_length=2,
choices=VENDOR_CHOICES,
default=CISCO,
)
device_model = models.ForeignKey(DeviceModel, on_delete=None)
device_part = models.ForeignKey(DevicePart, on_delete=None)
Does this makes sense.....?
you are having an m2m relation between device and device part so you can calculate total device price by adding pricing of each part mapped to device
Suppose you have 5 Devices of Model "M" and Modal M is made up of 10 Individual parts so pricing will be common for 5 devices so total cost should be of Modal not the individual device
But Over a period of time pricing of parts will change and you have to keep track of the total price of the device during its entry in the system
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.