私は既存のモデルクラスを分割しようとしています。元のクラスは最適ではないので、CustomerOrderからすべての顧客関連情報を新しいクラスCustomerに移動したいと考えています。 Djangoでこれを行う最善の方法は何ですか?django models.py - あるモデルクラスから別のモデルクラスに移行する
旧モデルクラス:
class CustomerOrder(models.Model):
# Customer information fields
first_name = models.CharField(max_length=200) # Customer first name
last_name = models.CharField(max_length=200) # Customer last name
email = models.EmailField() # Customer email address
address = models.CharField(max_length=255) # Address to deliver (e.g. 1532 Commonwealth St. Apt 302)
city = models.CharField(max_length=200) # City to deliver (e.g. Fullerton, CA 92014)
# Order information fields
note = models.TextField() # Any notes the customer may have about shipping
shipping_method = models.CharField(max_length=200) # Shipping in LA or OC
total_price = models.FloatField(default=0) # Total price of the order
delivery_date = models.DateField() # When to deliver the order. Order is "live" until the next
# day after delivery. So if delivery date is Jan 3, it's "live" until Jan 4.
order_date = models.DateField() # When the customer ordered
time_slot = models.CharField(max_length=200) # What time to deliver the product
is_cancelled = models.BooleanField(default=False) # If the order is cancelled or refunded, we mark it here.
created_at = models.DateTimeField(auto_now_add=True) # When the order entry was saved into database
updated_at = models.DateTimeField(auto_now=True) # When the order was last updated in database
def __str__(self):
return self.first_name + " " + self.last_name
新モデルクラス:
class Customer(models.Model):
first_name = models.CharField(max_length=200) # Customer first name
last_name = models.CharField(max_length=200) # Customer last name
email = models.EmailField() # Customer email address
address = models.CharField(max_length=255) # Address to deliver (e.g. 1532 Commonwealth St. Apt 302)
city = models.CharField(max_length=200) # City to deliver (e.g. Fullerton, CA 92014)
私は同様にそれらを削除したいので、古いモデルでの重複があります。
質問に不可欠な内容へのリンクは避けてください。 365日以内にあなたの質問は役に立たなくなるでしょう。リンクの内容をあなたの質問にコピーしてください。 – thebjorn
よく検討されたデータモデルについては、http://www.databaseanswers.org/data_models/を参照してください。多分この1つです:http://www.databaseanswers.org/data_models/e_commerce/index.htm – thebjorn
私はリンクを削除するように更新しました – JoshGumby87