Skip to content

Commit

Permalink
feat: [admin] added categories and add category
Browse files Browse the repository at this point in the history
  • Loading branch information
aabidsofi19 committed Feb 26, 2022
1 parent 86dc0bc commit 42d5008
Show file tree
Hide file tree
Showing 68 changed files with 2,641 additions and 1,828 deletions.
18 changes: 18 additions & 0 deletions apps/backend/Orders/migrations/0014_auto_20220219_0648.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.13 on 2022-02-19 06:48

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('Orders', '0013_auto_20220212_1244'),
]

operations = [
migrations.RenameField(
model_name='order',
old_name='Address',
new_name='address',
),
]
30 changes: 30 additions & 0 deletions apps/backend/Orders/migrations/0015_auto_20220219_0705.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 3.1.13 on 2022-02-19 07:05

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


class Migration(migrations.Migration):

dependencies = [
('Users', '0010_auto_20220219_0705'),
('Orders', '0014_auto_20220219_0648'),
]

operations = [
migrations.AlterField(
model_name='order',
name='address',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='Users.address'),
),
migrations.AlterField(
model_name='order',
name='customer',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Users.customer'),
),
migrations.AlterField(
model_name='orderitem',
name='customer',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Users.customer'),
),
]
6 changes: 3 additions & 3 deletions apps/backend/Orders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Create your models here.
class Order(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.DO_NOTHING)
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
paid = models.BooleanField(default=False)
payment_methods = (("0", "stripe_checkout"), ("1", "PaymentIntent"))

Expand Down Expand Up @@ -39,7 +39,7 @@ class Order(models.Model):
choices=Fullfilment_Statuses, default="Unfulfilled", max_length=50
)

address = models.ForeignKey(Address, on_delete=models.DO_NOTHING, null=True)
address = models.ForeignKey(Address, on_delete=models.PROTECT, null=True)
tax_percent = models.IntegerField(default=0)
discount_percent = models.IntegerField(default=0)
shipping_charges = models.IntegerField(default=0)
Expand Down Expand Up @@ -86,7 +86,7 @@ class OrderItem(models.Model):
product_id = models.CharField(max_length=100, null=False)
variation_id = models.CharField(null=False, max_length=50)
amount = models.IntegerField(null=False) # single item price
customer = models.ForeignKey(Customer, on_delete=models.DO_NOTHING)
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)

quantity = models.IntegerField(null=False)
Order_date = models.DateTimeField(auto_now_add=True, blank=True)
Expand Down
19 changes: 19 additions & 0 deletions apps/backend/Users/migrations/0009_auto_20220219_0648.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.1.13 on 2022-02-19 06:48

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


class Migration(migrations.Migration):

dependencies = [
('Users', '0008_auto_20220206_1710'),
]

operations = [
migrations.AlterField(
model_name='customer',
name='default_address',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='default_address', to='Users.address'),
),
]
18 changes: 18 additions & 0 deletions apps/backend/Users/migrations/0010_auto_20220219_0705.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.13 on 2022-02-19 07:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Users', '0009_auto_20220219_0648'),
]

operations = [
migrations.AlterField(
model_name='customer',
name='Addresses',
field=models.ManyToManyField(blank=True, to='Users.Address'),
),
]
49 changes: 28 additions & 21 deletions apps/backend/Users/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from django.db import models
from django.contrib.auth.models import AbstractUser
from typing import Optional,Iterable
from typing import Optional, Iterable

# from graphql_auth.models import UserStatus
class User(AbstractUser):
is_customer = models.BooleanField(default=False)
Expand All @@ -10,52 +10,59 @@ class User(AbstractUser):
# super().save(*args,**kwargs)
# if self.is_customer :
# Customer(user=self).save()

# @property
# def status(self):
# status = UserStatus.objects.get(user=self)
# print(status)
# return status

class DynamicUpdateFields:

def update_fields(self,update_values):
for attr,value in update_values.items():
if value :
setattr(self,attr,value)
class DynamicUpdateFields:
def update_fields(self, update_values):
for attr, value in update_values.items():
if value:
setattr(self, attr, value)
self.save()

class Address(models.Model,DynamicUpdateFields):
name=models.CharField(max_length=100)

class Address(models.Model, DynamicUpdateFields):
name = models.CharField(max_length=100)
pincode = models.CharField(max_length=6)
state = models.CharField(max_length=100)
country = models.CharField(max_length=100)
city = models.CharField(max_length=100)
town = models.CharField(max_length=100)
apartment_no = models.CharField(max_length=50)
# is_primary = models.BooleanField(default=False)
is_work= models.BooleanField(default=False)
is_home= models.BooleanField(default=True)
is_work = models.BooleanField(default=False)
is_home = models.BooleanField(default=True)
phone_number = models.CharField(max_length=13, null=False)

def __str__(self):
return self.pincode


class Customer(models.Model):
user = models.OneToOneField(
User, on_delete=models.CASCADE, primary_key=True)
phone_number = models.CharField(max_length=13, null=False,blank=True)
Addresses = models.ManyToManyField(Address,null=True,blank=True)
default_address=models.OneToOneField(Address,on_delete=models.SET_NULL,null=True,blank=True ,related_name="default_address")
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
phone_number = models.CharField(max_length=13, null=False, blank=True)
Addresses = models.ManyToManyField(Address, blank=True)
default_address = models.OneToOneField(
Address,
on_delete=models.CASCADE,
null=True,
blank=True,
related_name="default_address",
)
is_verified = models.BooleanField(default=False)
verification_methods = (
(1, 'phone'),
(2, 'email'),
(1, "phone"),
(2, "email"),
)
verified_by = models.IntegerField(
choices=verification_methods, null=True, blank=True
)
verified_by = models.IntegerField(choices=verification_methods,null=True,blank=True)
joined_on = models.DateField(auto_now_add=True, blank=True)

def __str__(self):
return str(self.user)

8 changes: 8 additions & 0 deletions apps/backend/Users/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
from cart.decorators import migrate_cart_to_db, migrate_cart_to_session


class UserStatusType(DjangoObjectType):
class Meta:
model = UserStatus


class UserType(DjangoObjectType):
class Meta:
model = User
Expand Down Expand Up @@ -55,6 +60,9 @@ class Meta:
"user__last_name": ["exact"],
"user__email": ["exact"],
"phone_number": ["exact"],
"user__status__verified": ["exact"],
"user__status__archived": ["exact"],
"user__is_active": ["exact"],
}


Expand Down
1 change: 1 addition & 0 deletions apps/backend/load_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import random
import json
from mongoengine import *
import
# connect('products',host='mongodb://localhost:27017')
# connect('products',host='mongodb://25.19.8.34:27017')
connect('zivero', host='mongodb+srv://test-user:[email protected]/zivero?retryWrites=true&w=majority')
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/shop/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Category(Document):
StringField(choices=gender_choices)
) # genders a category can have
# will help in updating filters if a category is selected to get the revent gender associated to it
brands = ListField(ReferenceField(Brand))
brands = ListField(ReferenceField(Brand, reverse_delete_rule=NULLIFY))
# will help in updating filters if a category is selected to get the relevent brands associated to it


Expand Down
Loading

0 comments on commit 42d5008

Please sign in to comment.