Problem in rendering the data from Postgres in Django views.py from two different models

14 views
Skip to first unread message

Hemanta Kumar

unread,
Feb 21, 2021, 12:06:37 PM2/21/21
to Django users
I am created an app name order whose models field look like this:-

from django.db import models
from ckeditor.fields import RichTextField
from datetime import datetime
# Create your models here.

class create_order(models.Model):

emb_choice=(
('Yes', 'Yes'),
('No', 'No'),
('Other', 'Other'),
)

wash_choice=(
('Yes', 'Yes'),
('No', 'No'),
('Other', 'Other'),
)

tape_choice=(
('Yes', 'Yes'),
('No', 'No'),
('Other', 'Other'),
)

x=datetime.now()
month_code_choice=(
('1-{}'.format(x.year), '1-{}'.format(x.year)),
('2-{}'.format(x.year), '2-{}'.format(x.year)),
('3-{}'.format(x.year), '3-{}'.format(x.year)),
('4-{}'.format(x.year), '4-{}'.format(x.year)),
('5-{}'.format(x.year), '5-{}'.format(x.year)),
('6-{}'.format(x.year), '6-{}'.format(x.year)),
('7-{}'.format(x.year), '7-{}'.format(x.year)),
('8-{}'.format(x.year), '8-{}'.format(x.year)),
('9-{}'.format(x.year), '9-{}'.format(x.year)),
('10-{}'.format(x.year), '10-{}'.format(x.year)),
('11-{}'.format(x.year), '11-{}'.format(x.year)),
('12-{}'.format(x.year), '12-{}'.format(x.year)),
)


merchant_name=models.CharField(max_length=255)
sample_type=models.CharField(max_length=255)
buyer_name=models.CharField(max_length=255)
style_type=models.CharField(max_length=255)
fabric_type=models.CharField(max_length=255)
fabric_article=models.CharField(max_length=255)
emb=models.CharField(choices=emb_choice, max_length=255)
wash=models.CharField(choices=wash_choice, max_length=255)
tape=models.CharField(choices=tape_choice, max_length=255)
description=RichTextField(blank=True)
in_house=models.DateField(default=datetime.now)
new_in_house=models.DateField(default=datetime.now)
delivery_date=models.DateField()
month_code=models.CharField(choices=month_code_choice, max_length=255)
qty_of_order=models.IntegerField()
bal_to_load=models.IntegerField()
created_at=models.DateField(editable=False,auto_now_add=True)
updated_at=models.DateTimeField(auto_now_add=True)

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


Now I created another app called "wherehouse". Whose models look like this:-

from django.db import models
from django.db.models.deletion import SET_NULL
from ckeditor.fields import RichTextField
from datetime import datetime
from order.models import create_order
# Create your models here.


class wherehouse_model(models.Model):

status_choice=(
('Confirm', 'Confirm'),
('Reject', 'Reject'),
)

product_id=models.OneToOneField(create_order, primary_key=True, on_delete=models.CASCADE)
description=RichTextField(blank=True)
status=models.CharField(choices=status_choice, max_length=255)

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

In this model I try to store the status of all the product which is created using "create_order" model.Now what happen this "wherehouse" app user confirming the product whether it is available or not. If he didn't respond to any product within 3days then the list of that product should be shown to his senior. So for that I have created another app named "seniorwherehouse". Whose models look lie this:-

from django.db import models
from wherehouse.models import wherehouse_model
from order.models import create_order
from ckeditor.fields import RichTextField
from datetime import datetime
# Create your models here.


class seniorwherehouse_model(models.Model):

status_choice=(
('Confirm', 'Confirm'),
('Reject', 'Reject'),
)

product_id=models.ForeignKey(create_order, on_delete=models.CASCADE, primary_key=True)
description=RichTextField(blank=True)
status=models.CharField(choices=status_choice, max_length=255)

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


Now in views of "seniorwherehouse" I tried this for viewing that product which is not either confirmed or rejected within 3 days, But it didn't work.Please help me to solve my issue. How can I do this.
Reply all
Reply to author
Forward
0 new messages