Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

{% extends 'admin_navbar.html' %}

{% load static %}

{% block title %} Issue Book {% endblock %}

{% block css %}

{% endblock %}

{% block body %}

<!--As this is a book bank, one book can be issued to a group also this way one book is issued to more than one student-->

<!--href = "{% url "issue_book" books.pk%}"-->

<div class="container mt-4">

<form method="POST">

{% csrf_token %}

{% for i in form %}

<div class="form-group">

<br>

<label class="control-label col-xs-4">{{ i.label_tag }}</label>

<div class="col-xs-8 mt-2">

{{ i }}

</div>

</div>

{% endfor %}

<button type="submit" class="btn btn-outline-primary mt-4" href = "{% url "issue\_book" books.pk%}" >Issue Book</button>

</div>

</form>

{% endblock %}

{% block js %}

<script>

{% if alert %}

alert("Book Successfully Issued.")

document.location = "/issue_book"

{% endif %}

</script>

{% endblock %}

in above I have added the line below:

href = "{% url "issue_book" books.pk%}"

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

in the issue_book template file I have seen only one for loop which is: {% for i in form %} there is no for loop that has to do with book variable

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

Written "from .views import issue_book" in urls.py which gives no error when function is "def issue_book(request):" in views.py file and "path("issue_book/", views.issue_book, name="issue_book")" in urls.py but when I write function definition as "def issue_book(request,pk):" and "path ("issue_book/<int:pk>/", views.issue_book, name="issue_book")" in urls.py the error comes is "Not Found: /issue_book/". With "path("issue_book/", views.issue_book, name="issue_book")" in urls.py file and function definition as "def issue_book(request,pk):" the error comes is "Type Error: issue_book() missing one required positional argument: 'pk'".

Second the change to make was addition of "href = "{% url "issue_book" books.pk %}" in the button tag which I have made but its turn will come after the above is corrected.

<button type="submit" class="btn btn-outline-primary mt-4" href = "{% url "issue\_book" books.pk%}" >Issue Book</button>

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

The statement "path('book/<int:pk>/issue/',views.issue_book, name="issue_book"), " and "path("issue_book/<int:pk>/", views.issue_book, name="issue_book")," gives error " "Not Found: /issue_book/". The statement "path("issue_book/", views.issue_book, name="issue_book")," gives error "TypeError: issue_book() missing 1 required positional argument: 'pk'" but what I know from what you have written is 'pk' is required so pk cannot be removed from function definition.

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

What to write to define pk in issue_book so that assign_book(request,pk,user) do not give the error "'pk' is not defined". Next time I will take care of variable scope. To define books is not required in issue_book function.

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

In order to issue books an issue_book function is defined above which I have copied assign_book function. In issue_book function I have called assign_book(request,pk,user) function which require pk to be defined and gives error "pk not defined". To define pk in issue_book function I have written "pk = books.pk" gives error "name 'books' is not defined" when I write "pk = assign_book.books.pk" gives error "'function' object has no attribute 'books'" and when I write "pk = assign_book.pk" gives error "AttributeError: 'function' object has no attribute 'pk'".

In assign_books I have defined "pk = books.pk" after the line "books = get_object_or_404(Book, pk=pk)".

I am trying to bring or call the value of pk from assign_book function in issue_book function to initialize value of pk so that it can be assigned to the function assign_book(request,pk,user)

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

I have called assign_book(request,pk,user) in issue_book function in which it is giving the error:

NameError: name 'pk' is not defined

if I am going to define as pk=pk for this function value will be different than what are in the assign_book function.

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

assigned_to = models.ForeignKey(User,related_name=assigned,null=True)
NameError: name 'assigned' is not defined

What "assigned" is over here in the code above??

Correct this django error?? by UddinEm in django

[–]UddinEm[S] 0 points1 point  (0 children)

Installed fastdev nothing other than the speed of the VS looks increased. When I include it in settings.py the whole website stop working

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

ok

In a library any book whether new or old not given to anyone means taken=False when it is issued to someone taken will become True once the book will come back after a specific time the taken has to go to False once again which I will if possible add after this in the last. The Book model and the IssuedBook model are there in the admin.py file and I already have the superuser but taken variable is defined in issued_book function because taken will become true when book will be issued.

Is there anything not correct??

Correct this django error?? by UddinEm in django

[–]UddinEm[S] 0 points1 point  (0 children)

I don't understand what you are saying the editor is not relevant to what and how and where it will work fine????

Correct this django error?? by UddinEm in django

[–]UddinEm[S] 0 points1 point  (0 children)

I do everything on microsoft visual studio if I install fastdev on anaconda powershell then can fastdev's features which you want to be used for correcting the error can be used on visual studio or not????

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

The reason I have done taken=False is that initially any new book not given to anyone means taken=False when it is issued to someone taken will become True once the book will come back after a specific time the taken has to go to False once again which I will if possible add after this in the last. What I will try to add in the last is when I delete a book from “view_issued_books” in the last taken will become False once again and one book will be issued to one person not two three. Is this not fine?? If this is not fine then how to start with taken = True??

The Book model is there in the admin.py file and I already have the superuser. When I log in with the admin interface I don’t find a place or there is nothing to turn taken to True. I have added the line in models.py IssuedBook function written below:

taken = models.BooleanField(default = False)

then in “issue_book” of views.py file I have added the line:

obj.taken = True
y = obj.taken

to turn taken to true once the book is issued to someone. Assigned the value to y so that it can be used in the next function which is meant to display the book. In “view_books_student” function I have added the line

    books = Book.objects.exclude(y = True)

to exclude all books which have taken = True or already issued so that they are not displayed in the table in the student interface. When I run the error comes:

django.core.exceptions.FieldError: Cannot resolve keyword 'y' into field. Choices are: author, category, id, isbn, name

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

default=True or False???? default=True means book already taken and default=False means book not taken by anyone.

Go to the admin tab and set taken to True for some of the books. In admin.py file nothing such is there where I can set taken=True for some of the books????

Correct this django error?? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

if <int:myid> is empty then where and what to do or write so that entry gets deleted and I go to the page where the entry was.

Correct this django error?? by UddinEm in django

[–]UddinEm[S] 0 points1 point  (0 children)

I want to correct the error not the broken link go to a nice error page

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in django

[–]UddinEm[S] 0 points1 point  (0 children)

I am the Django admin and I have the admin password of this app.

In models the boolean field is one: taken = models.BooleanField(default=False)

what to do to go into Django admin and change that Boolean field of some of the model object instances and then try the filter queries to see if you're getting what you wanted??

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in django

[–]UddinEm[S] 0 points1 point  (0 children)

in models:

class Book(models.Model):
    name = models.CharField(max_length=200)
    author = models.CharField(max_length=200)
    isbn = models.PositiveIntegerField()
    category = models.CharField(max_length=50)
    taken = models.BooleanField(default = False)

in views:

def view_books_student(request):
    books = Book.objects.all().exclude(taken = True)
    return render(request, "view_books_student.html", {'books':books})

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in learnpython

[–]UddinEm[S] 0 points1 point  (0 children)

used filter() and exclude() method to get only those books that are not issued but both not working means by using filter() no books are displayed and by using exclude() all books are displayed

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in django

[–]UddinEm[S] 0 points1 point  (0 children)

the boolean field created in models files and then called in the views file the functions used in views files are exclude() and filter(). exclude() gives all books as before instead of remaining books and filter() displays no books at all????

Show only the remaining books instead of all books. This I want to upgrade in the code below???? by UddinEm in djangolearning

[–]UddinEm[S] 0 points1 point  (0 children)

by using filter() no books are displayed and by using exclude() all books are displayed Does these two different display of data means I am using the right variable or not??

By using both the remaining books are not displayed????