Skip to content

Commit

Permalink
Fix some model weirdness
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethlove committed May 6, 2017
1 parent 49a59d5 commit 223f2a6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
42 changes: 42 additions & 0 deletions customers/migrations/0004_auto_20170506_1203.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-05-06 19:03
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('products', '0005_auto_20170415_1656'),
('customers', '0003_purchasitem'),
]

operations = [
migrations.CreateModel(
name='PurchaseItem',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quanity', models.IntegerField(default=1)),
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='products.Product')),
('purchase', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='customers.Purchase')),
],
),
migrations.RemoveField(
model_name='purchasitem',
name='product',
),
migrations.RemoveField(
model_name='purchasitem',
name='purchase',
),
migrations.DeleteModel(
name='PurchasItem',
),
migrations.AddField(
model_name='purchase',
name='items',
field=models.ManyToManyField(through='customers.PurchaseItem', to='products.Product'),
),
]
5 changes: 3 additions & 2 deletions customers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ class Purchase(models.Model):
discount_code = models.CharField(blank=True, default='', max_length=20)
total = models.DecimalField(max_digits=9, decimal_places=2)
shipped = models.BooleanField(default=False)
items = models.ManyToManyField('products.Product', through='PurchaseItem')


class PurchasItem(models.Model):
class PurchaseItem(models.Model):
product = models.ForeignKey('products.Product')
purchase = models.ForeignKey(Purchase, related_name='items')
purchase = models.ForeignKey(Purchase)
quanity = models.IntegerField(default=1)

0 comments on commit 223f2a6

Please sign in to comment.