Align customer models and database target to customerwebsite
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 24s
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 24s
This commit is contained in:
parent
02c1cfaae9
commit
13df02729b
3 changed files with 19 additions and 10 deletions
|
|
@ -87,7 +87,7 @@ jobs:
|
|||
echo "SELLER_DB_PASSWORD=vtechnosoft@123A" >> .env
|
||||
echo "SELLER_DB_HOST=127.0.0.1" >> .env
|
||||
echo "SELLER_DB_PORT=5432" >> .env
|
||||
echo "CUSTOMER_DB_NAME=customerprofile" >> .env
|
||||
echo "CUSTOMER_DB_NAME=customerwebsite" >> .env
|
||||
echo "CUSTOMER_DB_USER=vignesh" >> .env
|
||||
echo "CUSTOMER_DB_PASSWORD=vtechnosoft@123A" >> .env
|
||||
echo "CUSTOMER_DB_HOST=127.0.0.1" >> .env
|
||||
|
|
|
|||
|
|
@ -2,18 +2,24 @@ from django.db import models
|
|||
|
||||
class CustomerProfile(models.Model):
|
||||
user_id = models.IntegerField(unique=True)
|
||||
full_name = models.CharField(max_length=255)
|
||||
phone = models.CharField(max_length=50, blank=True, null=True)
|
||||
phone = models.CharField(max_length=20, blank=True, null=True)
|
||||
default_address = models.TextField(blank=True, null=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'customer_profiles'
|
||||
db_table = 'orders_customerprofile'
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.full_name
|
||||
from django.db import connections
|
||||
try:
|
||||
with connections['customer_db'].cursor() as cursor:
|
||||
cursor.execute("SELECT username FROM auth_user WHERE id = %s", [self.user_id])
|
||||
row = cursor.fetchone()
|
||||
return row[0] if row else f"Customer #{self.id}"
|
||||
except Exception:
|
||||
return f"Customer #{self.id}"
|
||||
|
||||
@property
|
||||
def email(self):
|
||||
|
|
@ -35,18 +41,21 @@ class CustomerProfile(models.Model):
|
|||
return "active"
|
||||
|
||||
class Order(models.Model):
|
||||
customer = models.ForeignKey(CustomerProfile, on_delete=models.DO_NOTHING, db_column='customer_id')
|
||||
customer = models.ForeignKey(CustomerProfile, on_delete=models.DO_NOTHING, to_field='user_id', db_column='user_id', related_name='orders')
|
||||
total_amount = models.DecimalField(max_digits=10, decimal_places=2)
|
||||
status = models.CharField(max_length=50, default='pending')
|
||||
status = models.CharField(max_length=20, default='pending')
|
||||
placed_at = models.DateTimeField(auto_now_add=True)
|
||||
razorpay_order_id = models.CharField(max_length=100, blank=True, null=True)
|
||||
razorpay_payment_id = models.CharField(max_length=100, blank=True, null=True)
|
||||
shipping_address = models.TextField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'orders'
|
||||
db_table = 'orders_order'
|
||||
|
||||
@property
|
||||
def merchant_transaction_id(self):
|
||||
return f"TXN_{self.id}"
|
||||
return self.razorpay_order_id or f"TXN_{self.id}"
|
||||
|
||||
@property
|
||||
def amount(self):
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ else:
|
|||
},
|
||||
'customer_db': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': os.getenv('CUSTOMER_DB_NAME', 'customer_website'),
|
||||
'NAME': os.getenv('CUSTOMER_DB_NAME', 'customerwebsite'),
|
||||
'USER': os.getenv('CUSTOMER_DB_USER', 'postgres'),
|
||||
'PASSWORD': os.getenv('CUSTOMER_DB_PASSWORD', 'postgres'),
|
||||
'HOST': os.getenv('CUSTOMER_DB_HOST', '127.0.0.1'),
|
||||
|
|
|
|||
Loading…
Reference in a new issue