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

library management system created #1

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

Conversation

rohan-saeed
Copy link
Owner

No description provided.

@rohan-saeed rohan-saeed requested a review from ahmed-arb October 30, 2023 07:18
Copy link
Collaborator

@ahmed-arb ahmed-arb left a comment

Choose a reason for hiding this comment

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

Your code needs a lot of improvement and you have derailed from the task completely. You were suppose to write an API with django rest framework. Please refer to this documentation and refactor your code:
https://www.django-rest-framework.org/
Moreover, always remember to include environment specific files/folders, like __pychache__, in your .gitignore file.

Comment on lines +17 to +18
return_date = models.DateField()
returned = models.BooleanField(default=False)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we have a return_date here when we have a separate table for returned books.

Comment on lines 22 to 36
class BookRequest(models.Model):
REQUEST_STATUS_CHOICES = (
('Pending', 'Pending'),
('Approved', 'Approved'),
('Rejected', 'Rejected'),
)
user = models.ForeignKey(User, on_delete=models.CASCADE)
book = models.ForeignKey(Book, on_delete=models.CASCADE)
request_date = models.DateTimeField(auto_now_add=True)
status = models.CharField(
max_length=20, choices=REQUEST_STATUS_CHOICES, default='Pending')
rejection_reason = models.TextField(blank=True, null=True)

def __str__(self):
return f'{self.user.username} requests {self.book.name}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can modify this table to store information about issued and returned books as well. This way we can get rid of BookReturn and BookIssue.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks for the feedback. I have updated the code.

Comment on lines 22 to 25
if user.has_perm("library_management.delete_book"):
return False
if user.has_perm("library_management.change_book"):
return False
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand If the user has permission why do we return false?

if user.has_perm("library_management.change_book"):
return True

if user.is_librarian == False:
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the above condition fails this condition would always be true. We can replace this redundant check with an else.

class BookSerializer(serializers.ModelSerializer):
class Meta:
model = Book
fields = '__all__'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Returning all fields is not a good practice because down the line if you need to add sensitive fields every related serializer would serialize that as well. You should list every field instead.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Got it.

Comment on lines 54 to 61

class BookRequestView(View):
template_name = 'book_request.html'

def get(self, request):
form = BookRequestForm()
return render(request, self.template_name, {'form': form})

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see permissions being applied here. Shouldn't users and librarian have different permissions, even serializers for this modal?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, user and librarian have separate permissions. I have updated the code.Kindly provide feedback

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good work on using environment variables for email settings.

Copy link
Collaborator

@Danyal-Faheem Danyal-Faheem Nov 6, 2023

Choose a reason for hiding this comment

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

# Register your models here
You should try to remove pre existing comments like this one

Copy link
Collaborator

@Danyal-Faheem Danyal-Faheem Nov 6, 2023

Choose a reason for hiding this comment

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

Good use of choices but we can utilize classes for choices as well. For example like this:

class MyModel(models.Model): class Month(models.IntegerChoices): JAN = 1, "JANUARY" FEB = 2, "FEBRUARY" MAR = 3, "MAR" # (...) month = models.PositiveSmallIntegerField( choices=Month.choices, default=Month.JAN )

You can refer to the 2nd answer in this [link](https://stackoverflow.com/questions/18676156/how-to-properly-use-the-choices-field-option-in-django) for more info

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we have a return_date field in models, why do we need to calculate it again?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good work on using inbuilt permission checks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you mixed up the read_only fields on LIbrarianIssueSerializer and UserIssueSerializer as the User should have all read_only fields and the Librarian should have access to all of them.

Same issue in LibrarianTicketSerializer and UserTicketSerializer.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We only need to filter the queryset for the user when the user has a USER role. The librarian role should be able to see all the elements in the table.

Why are we using the BookIssue model in the BookTicketDetail view?

users/models.py Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good use of is_librarian field.

We can once again utilize a class for the choices.

users/forms.py Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to shift to DRF for this one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good work on the is created validation check.

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.

3 participants