This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Porduct(models.Model): | |
title = models.CharField(max_length=255) | |
image = models.ImageField() | |
price = models.IntergerField() | |
def __str__(self): | |
return self.title |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from .models import Product | |
# Register your models here. | |
admin.site.register(Product) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from .models import Product | |
from .forms import PorductForm | |
# function based views | |
def product_detail_view(request,id): | |
product_obj = Product.objects.get(id=id) | |
context = {'product_obj':product_obj} | |
return render(request,'product_detail.html',context) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from django.views.generic import ListView,DetailView,CreateView,UpdateView,DeleteView | |
from .models import Product | |
from .forms import ProductForm | |
class ProductListView(ListView): | |
queryset = Product.objects.all() | |
template_name = 'product_view.html' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from djanogo import forms | |
from .models import Porduct | |
class PorductForm(forms.ModelForm): | |
class Meta : | |
model = Porduct | |
fields = ['title','image','price'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import path | |
# import function based view | |
from .views import (product_detail_view,product_list_view,product_create_view,product_update_view,product_delete_view) | |
# or class based views (this up to what your choise either you will work with cbv or fbv) | |
from .view import (ProductListView,ProductDetaiView,ProductCreateView,ProductUpdateView,ProductDeleteView) | |
urlpatterns = [ | |
# for function based view | |
path('',product_list_view) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import path | |
from django.conf.urls import include | |
from Product import urls as product_urls | |
urlpatterns = [ | |
path('admin/', admin.site.urls), | |
path('',include(product_urls)) | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Product list</tile> | |
</head> | |
<body> | |
{% for object in objects %} | |
<div> | |
<h3>{{object.title}}</h3> | |
<img src='{{object.image.url}}' /> | |
<h5> price {{object.price}} </h5> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>{{object.title}}</title> | |
</head> | |
<body> | |
<div> | |
<h3>{{object.title}}</h3> | |
<img src='{{object.image.url}}' /> | |
<h5>price {{object.price}}</h5> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>create Product</title> | |
</head> | |
<body> | |
<div> | |
<form method='POST' enctype="multipart/form-data"> {% csrf_token %} | |
{{form.media}} | |
{{form.as_p}} | |
<input type="submit" value="create" > |
OlderNewer