-
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?
Conversation
c0898d2
to
8ef16ae
Compare
@@ -7,6 +7,9 @@ class Product(models.Model): | |||
def __str__(self): | |||
return self.title | |||
|
|||
def get_absolute_url(self): |
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.
@@ -10,18 +10,6 @@ | |||
from management.models import Company | |||
|
|||
|
|||
class DashboardView(TemplateView): |
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.
Good Move.
management/views/product.py
Outdated
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
context['title'] = 'LBM' |
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.
'LBM-Product List'
same for rest and you might wanna change for company as well.
@@ -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 comment
The 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 comment
The 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.
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This does redirect and is under anchor tag.
<a href="{% url 'management:dashboard' %}">
<div class="icon-w">
<div class="os-icon os-icon-layout"></div>
</div>
<span>Dashboard</span>
</a>
@@ -7,6 +7,9 @@ class Product(models.Model): | |||
def __str__(self): | |||
return self.title | |||
|
|||
def get_absolute_url(self): |
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.
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 comment
The 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.
<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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Already been added in last commit.
`
<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."> {{ product.description }} </textarea>
</div>
</div>
</div>`
value="{{ product.title }}" | ||
data-error="Please input product's Name" | ||
minlength="3" maxlength="60" | ||
required="required" type="text"> |
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.
Description here as well
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.
Already been added in last commit.
`
<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."> {{ product.description }} </textarea>
</div>
</div>
</div>`
Ready for review.