0% found this document useful (0 votes)
88 views

Ecommerce Website Using Django.: Project in Python

The document describes models created for an ecommerce website using Django. It includes models for addresses, orders, order line items, queries, and products. The address, order, and order line item models store information for user addresses, order information like name and address, and details of individual items ordered. The query model stores contact queries. The product model defines fields for product name, description, price, and image.

Uploaded by

programmer
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views

Ecommerce Website Using Django.: Project in Python

The document describes models created for an ecommerce website using Django. It includes models for addresses, orders, order line items, queries, and products. The address, order, and order line item models store information for user addresses, order information like name and address, and details of individual items ordered. The query model stores contact queries. The product model defines fields for product name, description, price, and image.

Uploaded by

programmer
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CE376: PROGRAMMING IN PYTHON (Elective-II) 16CE068

PROJECT IN PYTHON
Ecommerce Website using Django.
a)Model address:

from django.db import models

from django.contrib.auth.models import User

from django.urls import reverse

# Create your models here.

class Address(models.Model):

user_id=models.ForeignKey(User, null=False,on_delete=models.CASCADE)

full_name = models.CharField(max_length=50, blank=False)

phone_number = models.CharField(max_length=20, blank=False)

country = models.CharField(max_length=40, blank=False)

postcode = models.CharField(max_length=20, blank=True)

town_or_city = models.CharField(max_length=40, blank=False)

street_address_1 = models.CharField(max_length=40, blank=False)

street_address_2 = models.CharField(max_length=40, blank=False)

county = models.CharField(max_length=40, blank=False)

b)model order:

from django.db import models

from products.models import Product

class Order(models.Model):

full_name = models.CharField(max_length=50, blank=False)

phone_number = models.CharField(max_length=20, blank=False)

55
CE376: PROGRAMMING IN PYTHON (Elective-II) 16CE068

country = models.CharField(max_length=40, blank=False)

postcode = models.CharField(max_length=20, blank=True)

town_or_city = models.CharField(max_length=40, blank=False)

street_address_1 = models.CharField(max_length=40, blank=False)

street_address_2 = models.CharField(max_length=40, blank=False)

county = models.CharField(max_length=40, blank=False)

date = models.DateField()

def __str__(self):

return "{0}-{1}-{2}".format(self.id, self.date, self.full_name)

class OrderLineItem(models.Model):

order = models.ForeignKey(Order, null=False,on_delete=models.CASCADE)

product = models.ForeignKey(Product, null=False,on_delete=models.CASCADE)

quantity = models.IntegerField(blank=False)

def __str__(self):

return "{0} {1} @ {2}".format(self.quantity, self.product.name, self.product.price)

c)model query:

from django.db import models

# Create your models here.

class Query(models.Model):

fullname=models.CharField(max_length=200)

email=models.EmailField()

content=models.TextField()

56
CE376: PROGRAMMING IN PYTHON (Elective-II) 16CE068

def __str__(self):

return self.email

d)model product

from django.db import models

class Product(models.Model):

name = models.CharField(max_length=254, default='')

description = models.TextField()

price = models.DecimalField(max_digits=10, decimal_places=2)

image = models.ImageField(upload_to='images')

def __str__(self):

return str(self.name)

57

You might also like