-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Product/crud added. #14
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
from django import forms | ||
from management.models import Company | ||
from management.models import Company, Product | ||
|
||
|
||
class CompanyForm(forms.ModelForm): | ||
class Meta: | ||
model = Company | ||
fields = '__all__' | ||
|
||
|
||
class ProductForm(forms.ModelForm): | ||
class Meta: | ||
model = Product | ||
fields = '__all__' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 3.0.2 on 2020-10-26 14:44 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('management', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='product', | ||
name='description', | ||
field=models.TextField(default=django.utils.timezone.now, max_length=220), | ||
preserve_default=False, | ||
), | ||
migrations.AlterField( | ||
model_name='company', | ||
name='company_type', | ||
field=models.CharField(choices=[('v', 'Vendor'), ('c', 'Client')], max_length=1), | ||
), | ||
migrations.AlterField( | ||
model_name='company', | ||
name='contact', | ||
field=models.CharField(max_length=30), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from dashboard import * | ||
from company import * | ||
from product import * |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from django.urls import reverse_lazy | ||
from django.contrib.auth.decorators import login_required | ||
from django.urls import reverse_lazy | ||
from django.views.generic import ( | ||
TemplateView, DetailView, | ||
DetailView, | ||
UpdateView, ListView, | ||
CreateView, DeleteView | ||
) | ||
|
@@ -10,25 +10,13 @@ | |
from management.models import Company | ||
|
||
|
||
class DashboardView(TemplateView): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good Move. |
||
template_name = 'home_page.html' | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
context['title'] = 'LBM' | ||
return context | ||
|
||
|
||
dashboard_view = login_required(DashboardView.as_view()) | ||
|
||
|
||
class CompanyProfileView(DetailView): | ||
model = Company | ||
template_name = 'company_management/view_company_profile.html' | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
context['title'] = 'LBM' | ||
context['title'] = 'LBM-Company List' | ||
return context | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.contrib.auth.decorators import login_required | ||
from django.views.generic import ( | ||
TemplateView | ||
) | ||
|
||
|
||
class DashboardView(TemplateView): | ||
template_name = 'home_page.html' | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
context['title'] = 'LBM-Dashboard' | ||
return context | ||
|
||
|
||
dashboard_view = login_required(DashboardView.as_view()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from django.contrib.auth.decorators import login_required | ||
from django.urls import reverse_lazy | ||
from django.views.generic import ( | ||
DetailView, | ||
UpdateView, ListView, | ||
CreateView, DeleteView | ||
) | ||
|
||
from management.forms import ProductForm | ||
from management.models import Product | ||
|
||
|
||
class ProductProfileView(DetailView): | ||
model = Product | ||
template_name = 'product_management/view_product_profile.html' | ||
|
||
def get_context_data(self, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do similar thing using Django Context Manager. We might do that in future. |
||
context = super().get_context_data(**kwargs) | ||
context['title'] = 'LBM-Product List' | ||
return context | ||
|
||
|
||
product_profile_view = login_required(ProductProfileView.as_view()) | ||
|
||
|
||
class ProductsListView(ListView): | ||
model = Product | ||
template_name = 'product_management/list_products.html' | ||
context_object_name = 'products' | ||
|
||
|
||
products_list_view = login_required(ProductsListView.as_view()) | ||
|
||
|
||
class ProductRegistrationView(CreateView): | ||
model = Product | ||
form_class = ProductForm | ||
context_object_name = 'product' | ||
template_name = 'product_management/create_product_profile.html' | ||
|
||
|
||
product_registration_view = login_required(ProductRegistrationView.as_view()) | ||
|
||
|
||
class ProductEditView(UpdateView): | ||
model = Product | ||
form_class = ProductForm | ||
context_object_name = 'product' | ||
template_name = 'product_management/edit_product_profile.html' | ||
|
||
|
||
product_edit_view = login_required(ProductEditView.as_view()) | ||
|
||
|
||
class ProductDeleteView(DeleteView): | ||
model = Product | ||
template_name = 'company_management/confirm_delete.html' | ||
success_url = reverse_lazy('management:list_products') | ||
|
||
|
||
product_delete_view = login_required(ProductDeleteView.as_view()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
</div> | ||
</div> | ||
<h1 class="up-header"> | ||
John Mayers | ||
{{ company.name }} | ||
</h1> | ||
<h5 class="up-sub-header"> | ||
Product Designer at Facebook | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. " Product Designer at Facebook" ??? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the default information. I haven't customised this page according to our needs, yet. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ <h1 class="menu-page-header"> | |
Page Header | ||
</h1> | ||
<ul class="main-menu"> | ||
<!-- Layouts --> | ||
<li class="sub-header"> | ||
<span>Layouts</span> | ||
</li> | ||
|
@@ -25,14 +26,8 @@ <h1 class="menu-page-header"> | |
<span>Dashboard</span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this redirect to dashboard as you remove the anchor ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does redirect and is under anchor tag.
|
||
</a> | ||
</li> | ||
{# <li>#} | ||
{# <a href="{% url 'management:dashboard' %}">#} | ||
{# <div class="icon-w">#} | ||
{# <div class="os-icon os-icon-layers"></div>#} | ||
{# </div>#} | ||
{# <span>Menu Styles</span>#} | ||
{# </a>#} | ||
{# </li>#} | ||
<!-- Layouts --> | ||
<!-- Company --> | ||
<li class="sub-header"> | ||
<span> Company </span> | ||
</li> | ||
|
@@ -52,5 +47,27 @@ <h1 class="menu-page-header"> | |
<span> Companies List </span> | ||
</a> | ||
</li> | ||
<!-- Company --> | ||
<!-- Product --> | ||
<li class="sub-header"> | ||
<span> Product </span> | ||
</li> | ||
<li> | ||
<a href="{% url 'management:create_product' %}"> | ||
<div class="icon-w"> | ||
<div class="os-icon os-icon-layers"></div> | ||
</div> | ||
<span> Create Product Profile </span> | ||
</a> | ||
</li> | ||
<li> | ||
<a href="{% url 'management:list_products' %}"> | ||
<div class="icon-w"> | ||
<div class="os-icon os-icon-file-text"></div> | ||
</div> | ||
<span> Products List </span> | ||
</a> | ||
</li> | ||
<!-- Product --> | ||
</ul> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{% extends 'base.html' %} | ||
{% load static %} | ||
{% block content %} | ||
<div class="content-i"> | ||
<div class="content-box"> | ||
<div class="element-wrapper"> | ||
<div class="element-box"> | ||
<form method="post"> | ||
{% csrf_token %} | ||
<div class="steps-w"> | ||
<div class="step-triggers"> | ||
<a class="step-trigger active" href="#stepContent1"> | ||
Create Product | ||
</a> | ||
</div> | ||
<div class="step-contents"> | ||
<div class="step-content active" id="stepContent1"> | ||
<div class="row"> | ||
<div class="col-sm-6"> | ||
<div class="form-group"> | ||
<label for=""> Name </label> | ||
<input class="form-control" name="title" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to update html files as well to shows description field. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already been added in last commit. `
|
||
data-error="Please input product's Name" | ||
placeholder="Product's Name" | ||
minlength="3" maxlength="60" | ||
required="required" type="text"> | ||
<div class="help-block form-text with-errors form-control-feedback"></div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-sm-6"> | ||
<div class="form-group"> | ||
<label> Description </label> | ||
<textarea class="form-control" rows="5" name="description" | ||
placeholder="Anything you would like to add."></textarea> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="form-buttons-w text-right"> | ||
<button class="btn btn-primary">Submit Form</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause code duplication you can create a helper method in a utils file. which takes the url as argument and returns the absolute url.
Now you will have to create method for each model.
If this is required by the model view we can keep this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the concept of get_absolute_url is understandable for me. I don't know how can I reduce code in utils.py or utils/absolute_urls.py. Could you refer some readings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its quite simple if its used by many classes it should be a seperate function. If its a functionality which contains multiple functions it should have its own class. If its core functionality it should exist in core files or should have its own core file.
If its a utility method and we can work without it. This should be moved to utility.py.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a two liner its fine to have it in all classes but comment is regarding the practice. Because having similar code repeated in all classes causes code duplication. Many ways to handle that. you can create your own parent model class which inherits from models.Model and have this method and then all other classes are inherited by that. or another way which is preferred here bcz its small functionality is to create a utility method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I am using builtin views like 'UpdateView', 'ListView' etc. These need an absolute urls that needs to be defined in Model. Apart from this, each model has different absolute url like Product model's absolute url leads to Product's list page while Company's functions leads to Company's list page.