π Online Library An interactive Django-based web application that allows users to register, upload, and read digital books, browse by genre or author, and leave comments. It also includes an example test model (Animal) to demonstrate Djangoβs testing framework.
π Features π€ User Authentication
Register, login, logout.
Update profile with avatar, bio, and favorite books.
π Books Management
Upload books with title, author, description, picture, and file.
Categorize books by multiple genres.
View, read, or delete books.
Add books to personal collection.
π¬ Comments
Leave comments on books.
Delete comments.
π§ Search
Search books by name, description, or genre.
π§βπ» Admin Panel
Manage all users, authors, books, genres, comments, and test data (Animal).
π§© Project Structure bash Copy Edit base/ βββ admin.py # Admin configuration βββ models.py # Database models βββ forms.py # Custom user and book forms βββ views.py # Application logic and routes βββ urls.py # URL mappings βββ tests.py # Unit tests βββ middleware.py # Custom middleware example βββ templates/base/ # HTML templates βββ static/ # Static files (CSS, JS, images) βοΈ Models Overview User: Extends Djangoβs AbstractUser with bio, avatar, and favorite books.
Book: Includes name, description, genre, author, file, and creator.
Author and Genre: Linked to books.
Comment: Linked to both User and Book.
Animal: Example test model (used in tests.py).
π§ Middleware Example NewMiddleware demonstrates how to execute logic before and after each request:
python Copy Edit class NewMiddleware: def call(self, request): print("Before") response = self.get_response(request) print("After") return response π§ͺ Testing Example tests.py includes a basic Django unit test:
python Copy Edit class AnimalTestCase(TestCase): def test_animal_can_speak(self): lion = Animal.objects.get(name='Lion') self.assertEquals(lion.speak(), 'The Lion says "Roar"') Run tests with:
bash Copy Edit python manage.py test
πΌοΈ Example URLs Page URL Home / About /about/ Contact /contact/ Login /login/ Register /register/ Profile /profile/<user_id>/ Add Book /add/
π§° Admin Management Access the admin interface at /admin/ to manage:
Users
Books
Authors
Genres
Comments
Animals
π§Ύ License This project is open-source and available under the MIT License.