Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Product/crud added. #14

wants to merge 5 commits into from

Conversation

quratulain25
Copy link
Collaborator

Ready for review.

@quratulain25 quratulain25 requested a review from Ayub-Khan October 6, 2020 05:33
@@ -7,6 +7,9 @@ class Product(models.Model):
def __str__(self):
return self.title

def get_absolute_url(self):
Copy link
Owner

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.

Copy link
Collaborator Author

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?

Copy link
Owner

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.

Copy link
Owner

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.

Copy link
Collaborator Author

@quratulain25 quratulain25 Dec 17, 2020

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.

management/models.py Show resolved Hide resolved
management/views/__init__.py Outdated Show resolved Hide resolved
management/urls.py Outdated Show resolved Hide resolved
@@ -10,18 +10,6 @@
from management.models import Company


class DashboardView(TemplateView):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Move.

management/views/main.py Outdated Show resolved Hide resolved

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = 'LBM'
Copy link
Owner

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" Product Designer at Facebook" ???

Copy link
Collaborator Author

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>
Copy link
Owner

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 ?

Copy link
Collaborator Author

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):
Copy link
Owner

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):
Copy link
Owner

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"
Copy link
Owner

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.

Copy link
Collaborator Author

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">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description here as well

Copy link
Collaborator Author

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>`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants