diff --git a/core/__pycache__/forms.cpython-311.pyc b/core/__pycache__/forms.cpython-311.pyc new file mode 100644 index 0000000..743835c Binary files /dev/null and b/core/__pycache__/forms.cpython-311.pyc differ diff --git a/core/__pycache__/models.cpython-311.pyc b/core/__pycache__/models.cpython-311.pyc index 60a1227..baa5259 100644 Binary files a/core/__pycache__/models.cpython-311.pyc and b/core/__pycache__/models.cpython-311.pyc differ diff --git a/core/__pycache__/urls.cpython-311.pyc b/core/__pycache__/urls.cpython-311.pyc index 42da972..2b28062 100644 Binary files a/core/__pycache__/urls.cpython-311.pyc and b/core/__pycache__/urls.cpython-311.pyc differ diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index 0581aad..8aa66a5 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/forms.py b/core/forms.py new file mode 100644 index 0000000..7dcbdc5 --- /dev/null +++ b/core/forms.py @@ -0,0 +1,25 @@ +from django import forms +from .models import Book, Transaction + +class BookForm(forms.ModelForm): + class Meta: + model = Book + fields = ['title', 'author', 'isbn', 'total_copies'] + widgets = { + 'title': forms.TextInput(attrs={'class': 'form-control'}), + 'author': forms.TextInput(attrs={'class': 'form-control'}), + 'isbn': forms.TextInput(attrs={'class': 'form-control'}), + 'total_copies': forms.NumberInput(attrs={'class': 'form-control'}), + } + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['total_copies'].initial = 1 + +class IssueBookForm(forms.ModelForm): + class Meta: + model = Transaction + fields = ['borrower_name'] + widgets = { + 'borrower_name': forms.TextInput(attrs={'class': 'form-control'}), + } diff --git a/core/migrations/0003_transaction.py b/core/migrations/0003_transaction.py new file mode 100644 index 0000000..48c47fc --- /dev/null +++ b/core/migrations/0003_transaction.py @@ -0,0 +1,25 @@ +# Generated by Django 5.2.7 on 2025-10-25 14:19 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0002_preload_books'), + ] + + operations = [ + migrations.CreateModel( + name='Transaction', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('borrower_name', models.CharField(max_length=200)), + ('issue_date', models.DateTimeField(auto_now_add=True)), + ('return_date', models.DateTimeField(blank=True, null=True)), + ('is_returned', models.BooleanField(default=False)), + ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.book')), + ], + ), + ] diff --git a/core/migrations/__pycache__/0003_transaction.cpython-311.pyc b/core/migrations/__pycache__/0003_transaction.cpython-311.pyc new file mode 100644 index 0000000..4ccf2cf Binary files /dev/null and b/core/migrations/__pycache__/0003_transaction.cpython-311.pyc differ diff --git a/core/models.py b/core/models.py index e6c3602..e24712a 100644 --- a/core/models.py +++ b/core/models.py @@ -8,4 +8,14 @@ class Book(models.Model): available_copies = models.PositiveIntegerField(default=1) def __str__(self): - return self.title \ No newline at end of file + return self.title + +class Transaction(models.Model): + book = models.ForeignKey(Book, on_delete=models.CASCADE) + borrower_name = models.CharField(max_length=200) + issue_date = models.DateTimeField(auto_now_add=True) + return_date = models.DateTimeField(null=True, blank=True) + is_returned = models.BooleanField(default=False) + + def __str__(self): + return f"{self.book.title} - {self.borrower_name}" \ No newline at end of file diff --git a/core/templates/core/add_book.html b/core/templates/core/add_book.html new file mode 100644 index 0000000..cea3144 --- /dev/null +++ b/core/templates/core/add_book.html @@ -0,0 +1,42 @@ +{% extends 'base.html' %} + +{% block title %} + Add Book - {{ project_name }} +{% endblock title %} + +{% block content %} +
Browse our collection of available books.
+Browse our collection of available books.
+History of all book issues and returns.
+| Book Title | +Borrower Name | +Issue Date | +Return Date | +Status | +Actions | +
|---|---|---|---|---|---|
| {{ transaction.book.title }} | +{{ transaction.borrower_name }} | +{{ transaction.issue_date|date:"Y-m-d H:i" }} | +{{ transaction.return_date|date:"Y-m-d H:i"|default:"--" }} | ++ {% if transaction.is_returned %} + Returned + {% else %} + Issued + {% endif %} + | ++ {% if not transaction.is_returned %} + Return + {% endif %} + | +
| No transactions found. | +|||||