Reputation: 5941
I'm looking for suggestions on creating a Django model structure for a shipping table, can you help? I wanted to kind of simple.. This is the stuff I want to store :
| Fedex | UPS | USPS
------------------------------------------------------------------
GROUND | Home Delivery | Ground | Parcel Select
3DAY | Express Saver | 3 Day Select | Priority or First Class
2DAY | 2Day | 2nd Day Air | Priority or First Class
etc | .. | .. | ..
I would like to create a Model(s) out of these, but I feel like I'm just creating a mess and my thinking is totally off. Here was my thinking, and Im not satisfied with it:
class ShippingMethod(models.Mod
title = models.CharField(
max_length = 20,
choices = SHIPPING_TITLES, # Just a list of Fedex/UPS etc
default = "fedex"
)
service = models.CharField(
max_length = 20,
choices = SHIPPING_SERVICES, # Just a list of Ground, 2day, etc
default = "GROUND"
# This model is lacking the "Description", eg: "Parcel Select, 2nd Day Air".
I didn't want to make three model
ShippingMethod -- UPS, USPS, Fedex
ShippingType -- Ground, 2Day
ShippingDescription -- "Parcel Select, 2nd Day Air"
I feel like I've just started over-complicated thing.. Any advice would be appreciated :)
Upvotes: 0
Views: 564
Reputation: 8285
I would imagine you will be stuck making three models. However, I would suggest making your ShippingMethod (UPS, USPS, FedEx) model, and your ShippingType (Ground, 2 Day, 3 Day, etc.), then the third model a ShippingMethodType model which ties the other two like:
ShippingMethodType(models.Model):
shipping_method = ForeignKey(ShippingMethod)
shipping_type = ForeignKey(ShippingType)
This way you can display the ShippingMethodType to select which will be a combination of the method and type and what it is called for that shipper. That's how I would do it, and I can't think of any more elegant way, other than this possibility:
from django.db import models
Shipper(models.Model)
name = models.CharField(max_length=16)
.
.
ground = models.CharField(max_length=16)
two_day = models.CharField(max_length=16)
three_day = models.CharField(max_length=16)
.
.
def shipPackage(self):
.
<some default functionality for all shippers>
.
ShipperUPS(Shipper):
.
<any UPS-specific fields>
.
.
def shipPackage(self):
.
<UPS-specific functionality>
super(Shipper, self).shipPackage()
ShipperUSPS(Shipper):
.
.
<overloaded USPS methods>
ShipperFedEx(Shipper):
.
.
<overloaded FedEx methods>
Something like this could come in handy, or may be overkill, depending on your specifications. But, I don't think you can get away with not using multiple models.
Upvotes: 2