diff --git a/crm1_v9_dynamic_urls_templates/accounts/__pycache__/__init__.cpython-37.pyc b/crm1_v9_dynamic_urls_templates/accounts/__pycache__/__init__.cpython-37.pyc
new file mode 100644
index 0000000..db7a15a
Binary files /dev/null and b/crm1_v9_dynamic_urls_templates/accounts/__pycache__/__init__.cpython-37.pyc differ
diff --git a/crm1_v9_dynamic_urls_templates/accounts/__pycache__/admin.cpython-37.pyc b/crm1_v9_dynamic_urls_templates/accounts/__pycache__/admin.cpython-37.pyc
new file mode 100644
index 0000000..5180e50
Binary files /dev/null and b/crm1_v9_dynamic_urls_templates/accounts/__pycache__/admin.cpython-37.pyc differ
diff --git a/crm1_v9_dynamic_urls_templates/accounts/__pycache__/models.cpython-37.pyc b/crm1_v9_dynamic_urls_templates/accounts/__pycache__/models.cpython-37.pyc
new file mode 100644
index 0000000..bae1532
Binary files /dev/null and b/crm1_v9_dynamic_urls_templates/accounts/__pycache__/models.cpython-37.pyc differ
diff --git a/crm1_v9_dynamic_urls_templates/accounts/__pycache__/urls.cpython-37.pyc b/crm1_v9_dynamic_urls_templates/accounts/__pycache__/urls.cpython-37.pyc
new file mode 100644
index 0000000..e1d3a0e
Binary files /dev/null and b/crm1_v9_dynamic_urls_templates/accounts/__pycache__/urls.cpython-37.pyc differ
diff --git a/crm1_v9_dynamic_urls_templates/accounts/__pycache__/views.cpython-37.pyc b/crm1_v9_dynamic_urls_templates/accounts/__pycache__/views.cpython-37.pyc
new file mode 100644
index 0000000..9d4845a
Binary files /dev/null and b/crm1_v9_dynamic_urls_templates/accounts/__pycache__/views.cpython-37.pyc differ
diff --git a/crm1_v9_dynamic_urls_templates/accounts/admin.py b/crm1_v9_dynamic_urls_templates/accounts/admin.py
new file mode 100644
index 0000000..4b4f5a4
--- /dev/null
+++ b/crm1_v9_dynamic_urls_templates/accounts/admin.py
@@ -0,0 +1,10 @@
+from django.contrib import admin
+
+# Register your models here.
+
+from .models import *
+
+admin.site.register(Customer)
+admin.site.register(Product)
+admin.site.register(Tag)
+admin.site.register(Order)
\ No newline at end of file
diff --git a/crm1_v9_dynamic_urls_templates/accounts/apps.py b/crm1_v9_dynamic_urls_templates/accounts/apps.py
new file mode 100644
index 0000000..3cab1e0
--- /dev/null
+++ b/crm1_v9_dynamic_urls_templates/accounts/apps.py
@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class AccountsConfig(AppConfig):
+ name = 'accounts'
diff --git a/crm1_v9_dynamic_urls_templates/accounts/migrations/0001_initial.py b/crm1_v9_dynamic_urls_templates/accounts/migrations/0001_initial.py
new file mode 100644
index 0000000..4fb1876
--- /dev/null
+++ b/crm1_v9_dynamic_urls_templates/accounts/migrations/0001_initial.py
@@ -0,0 +1,24 @@
+# Generated by Django 3.0 on 2019-12-02 22:15
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Customer',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=200, null=True)),
+ ('phone', models.CharField(max_length=200, null=True)),
+ ('email', models.CharField(max_length=200, null=True)),
+ ('date_created', models.DateTimeField(auto_now_add=True, null=True)),
+ ],
+ ),
+ ]
diff --git a/crm1_v9_dynamic_urls_templates/accounts/migrations/0002_order_product.py b/crm1_v9_dynamic_urls_templates/accounts/migrations/0002_order_product.py
new file mode 100644
index 0000000..8b5269f
--- /dev/null
+++ b/crm1_v9_dynamic_urls_templates/accounts/migrations/0002_order_product.py
@@ -0,0 +1,32 @@
+# Generated by Django 3.0 on 2019-12-02 22:35
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('accounts', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Order',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('date_created', models.DateTimeField(auto_now_add=True, null=True)),
+ ('status', models.CharField(choices=[('Pending', 'Pending'), ('Out for delivery', 'Out for delivery'), ('Delivered', 'Delivered')], max_length=200, null=True)),
+ ],
+ ),
+ migrations.CreateModel(
+ name='Product',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=200, null=True)),
+ ('price', models.FloatField(null=True)),
+ ('category', models.CharField(choices=[('Indoor', 'Indoor'), ('Out Door', 'Out Door')], max_length=200, null=True)),
+ ('description', models.CharField(max_length=200, null=True)),
+ ('date_created', models.DateTimeField(auto_now_add=True, null=True)),
+ ],
+ ),
+ ]
diff --git a/crm1_v9_dynamic_urls_templates/accounts/migrations/0003_auto_20191203_1454.py b/crm1_v9_dynamic_urls_templates/accounts/migrations/0003_auto_20191203_1454.py
new file mode 100644
index 0000000..0d2a53b
--- /dev/null
+++ b/crm1_v9_dynamic_urls_templates/accounts/migrations/0003_auto_20191203_1454.py
@@ -0,0 +1,24 @@
+# Generated by Django 3.0 on 2019-12-03 22:54
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('accounts', '0002_order_product'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='order',
+ name='customer',
+ field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounts.Customer'),
+ ),
+ migrations.AddField(
+ model_name='order',
+ name='product',
+ field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounts.Product'),
+ ),
+ ]
diff --git a/crm1_v9_dynamic_urls_templates/accounts/migrations/0004_auto_20191203_1502.py b/crm1_v9_dynamic_urls_templates/accounts/migrations/0004_auto_20191203_1502.py
new file mode 100644
index 0000000..71ada74
--- /dev/null
+++ b/crm1_v9_dynamic_urls_templates/accounts/migrations/0004_auto_20191203_1502.py
@@ -0,0 +1,25 @@
+# Generated by Django 3.0 on 2019-12-03 23:02
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('accounts', '0003_auto_20191203_1454'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Tag',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=200, null=True)),
+ ],
+ ),
+ migrations.AddField(
+ model_name='order',
+ name='tags',
+ field=models.ManyToManyField(to='accounts.Tag'),
+ ),
+ ]
diff --git a/crm1_v9_dynamic_urls_templates/accounts/migrations/0005_auto_20191203_1515.py b/crm1_v9_dynamic_urls_templates/accounts/migrations/0005_auto_20191203_1515.py
new file mode 100644
index 0000000..7e175c2
--- /dev/null
+++ b/crm1_v9_dynamic_urls_templates/accounts/migrations/0005_auto_20191203_1515.py
@@ -0,0 +1,22 @@
+# Generated by Django 3.0 on 2019-12-03 23:15
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('accounts', '0004_auto_20191203_1502'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='order',
+ name='tags',
+ ),
+ migrations.AddField(
+ model_name='product',
+ name='tags',
+ field=models.ManyToManyField(to='accounts.Tag'),
+ ),
+ ]
diff --git a/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0001_initial.cpython-37.pyc b/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0001_initial.cpython-37.pyc
new file mode 100644
index 0000000..22267cd
Binary files /dev/null and b/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0001_initial.cpython-37.pyc differ
diff --git a/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0002_order_product.cpython-37.pyc b/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0002_order_product.cpython-37.pyc
new file mode 100644
index 0000000..c07451c
Binary files /dev/null and b/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0002_order_product.cpython-37.pyc differ
diff --git a/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0003_auto_20191203_1454.cpython-37.pyc b/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0003_auto_20191203_1454.cpython-37.pyc
new file mode 100644
index 0000000..890d0fa
Binary files /dev/null and b/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0003_auto_20191203_1454.cpython-37.pyc differ
diff --git a/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0004_auto_20191203_1502.cpython-37.pyc b/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0004_auto_20191203_1502.cpython-37.pyc
new file mode 100644
index 0000000..152a790
Binary files /dev/null and b/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0004_auto_20191203_1502.cpython-37.pyc differ
diff --git a/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0005_auto_20191203_1515.cpython-37.pyc b/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0005_auto_20191203_1515.cpython-37.pyc
new file mode 100644
index 0000000..c9ce136
Binary files /dev/null and b/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/0005_auto_20191203_1515.cpython-37.pyc differ
diff --git a/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/__init__.cpython-37.pyc b/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/__init__.cpython-37.pyc
new file mode 100644
index 0000000..a3ca9e1
Binary files /dev/null and b/crm1_v9_dynamic_urls_templates/accounts/migrations/__pycache__/__init__.cpython-37.pyc differ
diff --git a/crm1_v9_dynamic_urls_templates/accounts/models.py b/crm1_v9_dynamic_urls_templates/accounts/models.py
new file mode 100644
index 0000000..3fe09bf
--- /dev/null
+++ b/crm1_v9_dynamic_urls_templates/accounts/models.py
@@ -0,0 +1,52 @@
+from django.db import models
+
+# Create your models here.
+
+class Customer(models.Model):
+ name = models.CharField(max_length=200, null=True)
+ phone = models.CharField(max_length=200, null=True)
+ email = models.CharField(max_length=200, null=True)
+ date_created = models.DateTimeField(auto_now_add=True, null=True)
+
+ def __str__(self):
+ return self.name
+
+
+class Tag(models.Model):
+ name = models.CharField(max_length=200, null=True)
+
+ def __str__(self):
+ return self.name
+
+class Product(models.Model):
+ CATEGORY = (
+ ('Indoor', 'Indoor'),
+ ('Out Door', 'Out Door'),
+ )
+
+ name = models.CharField(max_length=200, null=True)
+ price = models.FloatField(null=True)
+ category = models.CharField(max_length=200, null=True, choices=CATEGORY)
+ description = models.CharField(max_length=200, null=True, blank=True)
+ date_created = models.DateTimeField(auto_now_add=True, null=True)
+ tags = models.ManyToManyField(Tag)
+
+ def __str__(self):
+ return self.name
+
+class Order(models.Model):
+ STATUS = (
+ ('Pending', 'Pending'),
+ ('Out for delivery', 'Out for delivery'),
+ ('Delivered', 'Delivered'),
+ )
+
+ customer = models.ForeignKey(Customer, null=True, on_delete= models.SET_NULL)
+ product = models.ForeignKey(Product, null=True, on_delete= models.SET_NULL)
+ date_created = models.DateTimeField(auto_now_add=True, null=True)
+ status = models.CharField(max_length=200, null=True, choices=STATUS)
+
+
+
+
+
diff --git a/crm1_v9_dynamic_urls_templates/accounts/queryDemos.py b/crm1_v9_dynamic_urls_templates/accounts/queryDemos.py
new file mode 100644
index 0000000..8f96d7f
--- /dev/null
+++ b/crm1_v9_dynamic_urls_templates/accounts/queryDemos.py
@@ -0,0 +1,69 @@
+#***(1)Returns all customers from customer table
+customers = Customer.objects.all()
+
+#(2)Returns first customer in table
+firstCustomer = Customer.objects.first()
+
+#(3)Returns last customer in table
+lastCustomer = Customer.objects.last()
+
+#(4)Returns single customer by name
+customerByName = Customer.objects.get(name='Peter Piper')
+
+#***(5)Returns single customer by name
+customerById = Customer.objects.get(id=4)
+
+#***(6)Returns all orders related to customer (firstCustomer variable set above)
+firstCustomer.order_set.all()
+
+#(7)***Returns orders customer name: (Query parent model values)
+order = Order.objects.first()
+parentName = order.customer.name
+
+#(8)***Returns products from products table with value of "Out Door" in category attribute
+products = Product.objects.filter(category="Out Door")
+
+#(9)***Order/Sort Objects by id
+leastToGreatest = Product.objects.all().order_by('id')
+greatestToLeast = Product.objects.all().order_by('-id')
+
+
+#(10) Returns all products with tag of "Sports": (Query Many to Many Fields)
+productsFiltered = Product.objects.filter(tags__name="Sports")
+
+'''
+(11)Bonus
+Q: If the customer has more than 1 ball, how would you reflect it in the database?
+
+A: Because there are many different products and this value changes constantly you would most
+likly not want to store the value in the database but rather just make this a function we can run
+each time we load the customers profile
+'''
+
+#Returns the total count for number of time a "Ball" was ordered by the first customer
+ballOrders = firstCustomer.order_set.filter(product__name="Ball").count()
+
+#Returns total count for each product orderd
+allOrders = {}
+
+for order in firstCustomer.order_set.all():
+ if order.product.name in allOrders:
+ allOrders[order.product.name] += 1
+ else:
+ allOrders[order.product.name] = 1
+
+#Returns: allOrders: {'Ball': 2, 'BBQ Grill': 1}
+
+
+#RELATED SET EXAMPLE
+class ParentModel(models.Model):
+ name = models.CharField(max_length=200, null=True)
+
+class ChildModel(models.Model):
+ parent = models.ForeignKey(ParentModel)
+ name = models.CharField(max_length=200, null=True)
+
+parent = ParentModel.objects.first()
+#Returns all child models related to parent
+parent.childmodel_set.all()
+
diff --git a/crm1_v9_dynamic_urls_templates/accounts/templates/accounts/customer.html b/crm1_v9_dynamic_urls_templates/accounts/templates/accounts/customer.html
new file mode 100644
index 0000000..f2128d2
--- /dev/null
+++ b/crm1_v9_dynamic_urls_templates/accounts/templates/accounts/customer.html
@@ -0,0 +1,81 @@
+{% extends 'accounts/main.html' %}
+
+{% block content %}
+
+
+
+
Email: {{customer.email}}
+Phone: {{customer.phone}}
+Customer | +Phone | +
---|---|
{{customer.name}} | +{{customer.phone}} | +
Product | +Date Orderd | +Status | +Update | +Remove | +
---|---|---|---|---|
{{order.product}} | +{{order.date_created}} | +{{order.status}} | +Update | +Delete | + +
Product | +Category | +Price | +
---|---|---|
{{i.name}} | +{{i.category}} | +{{i.price}} | +