This commit is contained in:
Mohamad Jenbaz 2025-04-22 13:40:09 +02:00
parent 63dffd1d80
commit 63556a1ac3
14 changed files with 221 additions and 344 deletions

Binary file not shown.

View File

@ -10,7 +10,7 @@ Function views
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconftesting
Including another URLconftesting test
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
@ -19,5 +19,5 @@ from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls), # Admin site
path('', include('Sheets.urls')), # Sheets app URLs
path('', include('sheets.urls')), # Sheets app URLs
]

View File

@ -1,5 +1,6 @@
# Generated by Django 5.1.3 on 2024-12-04 13:22
# Generated by Django 5.1.5 on 2025-04-15 10:13
import django.db.models.deletion
from django.db import migrations, models
@ -12,10 +13,31 @@ class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
name='Sheet',
name='Client',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('address', models.TextField()),
],
),
migrations.CreateModel(
name='ExcelEntry',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('age', models.IntegerField()),
('email', models.EmailField(max_length=254)),
('date_joined', models.DateField(auto_now_add=True)),
('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='sheets.client')),
],
),
migrations.CreateModel(
name='SecondTableEntry',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('age', models.IntegerField()),
('email', models.EmailField(max_length=254)),
('date_joined', models.DateField(auto_now_add=True)),
('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='sheets.client')),
],
),
]

View File

@ -1,46 +0,0 @@
# Generated by Django 5.1.3 on 2024-12-04 14:19
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sheets', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='MainColumn',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('sheet', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='main_columns', to='sheets.sheet')),
],
),
migrations.CreateModel(
name='Row',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sheet', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rows', to='sheets.sheet')),
],
),
migrations.CreateModel(
name='SubColumn',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('main_column', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sub_columns', to='sheets.maincolumn')),
],
),
migrations.CreateModel(
name='Cell',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('value', models.CharField(blank=True, max_length=255, null=True)),
('row', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cells', to='sheets.row')),
('sub_column', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cells', to='sheets.subcolumn')),
],
),
]

View File

@ -1,50 +0,0 @@
# Generated by Django 5.1.4 on 2024-12-10 07:27
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sheets', '0002_maincolumn_row_subcolumn_cell'),
]
operations = [
migrations.RemoveField(
model_name='maincolumn',
name='sheet',
),
migrations.RemoveField(
model_name='subcolumn',
name='main_column',
),
migrations.RemoveField(
model_name='row',
name='sheet',
),
migrations.RenameModel(
old_name='Sheet',
new_name='Parent',
),
migrations.CreateModel(
name='Child',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('description', models.CharField(max_length=200)),
('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='children', to='sheets.parent')),
],
),
migrations.DeleteModel(
name='Cell',
),
migrations.DeleteModel(
name='MainColumn',
),
migrations.DeleteModel(
name='SubColumn',
),
migrations.DeleteModel(
name='Row',
),
]

View File

@ -1,29 +0,0 @@
# Generated by Django 5.1.5 on 2025-01-22 13:05
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sheets', '0003_remove_maincolumn_sheet_remove_subcolumn_main_column_and_more'),
]
operations = [
migrations.CreateModel(
name='ExcelEntry',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('age', models.IntegerField()),
('email', models.EmailField(max_length=254)),
('date_joined', models.DateField(auto_now_add=True)),
],
),
migrations.DeleteModel(
name='Child',
),
migrations.DeleteModel(
name='Parent',
),
]

View File

@ -1,23 +0,0 @@
# Generated by Django 5.1.5 on 2025-02-17 10:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sheets', '0004_excelentry_delete_child_delete_parent'),
]
operations = [
migrations.CreateModel(
name='SecondTableEntry',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('age', models.IntegerField()),
('email', models.EmailField(max_length=254)),
('date_joined', models.DateField(auto_now_add=True)),
],
),
]

View File

@ -1,21 +0,0 @@
# Generated by Django 5.1.5 on 2025-04-08 11:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sheets', '0005_secondtableentry'),
]
operations = [
migrations.CreateModel(
name='Client',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('address', models.TextField()),
],
),
]

View File

@ -8,19 +8,13 @@ class Client(models.Model):
return self.name
class ExcelEntry(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField()
email = models.EmailField()
date_joined = models.DateField(auto_now_add=True)
def __str__(self):
return self.name
class SecondTableEntry(models.Model):
name = models.CharField(max_length=100)
client = models.ForeignKey(Client, on_delete=models.CASCADE)
age = models.IntegerField()
email = models.EmailField()
date_joined = models.DateField(auto_now_add=True)
def __str__(self):
return self.name
class SecondTableEntry(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE)
age = models.IntegerField()
email = models.EmailField()
date_joined = models.DateField(auto_now_add=True)

View File

@ -109,7 +109,6 @@
</head>
<body>
<a href="/" class="btn-go-back">&#8592; Back to Main</a>
<div class="container">
<h2>Clients Table</h2>
@ -162,10 +161,10 @@
<div style="margin-top: 30px; text-align: center;">
<a href="{% url 'table_one' %}">
<button class="add-row-btn">Go to Table One</button>
<button class="add-row-btn">Go to Helium input</button>
</a>
<a href="{% url 'table_two' %}">
<button class="add-row-btn">Go to Table Two</button>
<button class="add-row-btn">Go to Table output</button>
</a>
</div>
@ -189,20 +188,18 @@
let address = $('#add-address').val();
$.ajax({
url: `/add-entry/${currentModelName}/`,
url: `/add-entry/Client/`,
method: 'POST',
data: {
'name': name,
'address': address,
'age': 0,
'email': 'none@example.com',
'csrfmiddlewaretoken': '{{ csrf_token }}'
},
success: function (response) {
let rowCount = $('tbody tr').length + 1;
let newRow = `
<tr data-id="${response.id}">
<td>${rowCount}</td> <!-- Serial number -->
<td>${rowCount}</td>
<td>${response.id}</td>
<td>${response.name}</td>
<td>${response.address}</td>
@ -214,6 +211,9 @@
`;
$('tbody').append(newRow);
$('#add-popup').fadeOut();
},
error: function (xhr) {
alert('Failed to add client: ' + xhr.responseText);
}
});
});
@ -272,7 +272,14 @@
success: function (response) {
if (response.status === 'success') {
row.fadeOut(300, function () { $(this).remove(); });
} else {
alert('Delete failed: ' + response.message);
}
},
error: function (xhr, status, error) {
alert('Delete request failed:\n' + xhr.responseText);
console.log('Error:', error);
console.log('Status:', status);
}
});
});

View File

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Excel-like Table</title>
<title>Helium Input</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css" />
@ -14,11 +14,6 @@
padding: 20px;
background-color: #f4f4f9;
}
.container {
display: flex;
justify-content: space-between;
gap: 20px;
}
.table-container {
width: 48%;
background-color: white;
@ -56,11 +51,11 @@
cursor: pointer;
font-size: 14px;
}
.edit-btn {
.edit-btn-one {
background-color: #28a745;
color: white;
}
.delete-btn {
.delete-btn-one {
background-color: #dc3545;
color: white;
}
@ -76,7 +71,7 @@
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
z-index: 1000;
}
.popup input {
.popup input, .popup select {
display: block;
margin-bottom: 10px;
width: 100%;
@ -115,92 +110,90 @@
</head>
<body>
<div class="d-flex justify-content-start mb-2">
<!-- "Go to Clients" button at top-left -->
<a href="{% url 'clients_list' %}" class="btn btn-outline-primary">
&#8678; Go to Clients
</a>
</div>
<a href="{% url 'clients_list' %}" class="btn btn-outline-primary">
&#8678; Go to Clients
</a>
<h2>Excel-like Table</h2>
<div class="container">
<!-- First Table -->
<div class="table-container">
<button class="add-row-btn" id="add-row-1">Add Row</button>
<table id="table-1">
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Email</th>
<th>Date Joined</th>
<th>Actions</th>
<h2>Helium Input</h2>
<div class="table-container">
<button class="add-row-btn" id="add-row-one">Add Row</button>
<table id="table-one">
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Client</th>
<th>Entry 1</th>
<th>Entry 2</th>
<th>Date Joined</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entry in entries_table1 %}
<tr data-id="{{ entry.id }}">
<td>{{ forloop.counter }}</td>
<td>{{ entry.id }}</td>
<td>{{ entry.client.name }}</td>
<td>{{ entry.age }}</td>
<td>{{ entry.email }}</td>
<td>{{ entry.date_joined }}</td>
<td class="actions">
<button class="edit-btn-one">Edit</button>
<button class="delete-btn-one">Delete</button>
</td>
</tr>
</thead>
<tbody>
{% for entry in entries_table1 %}
<tr data-id="{{ entry.id }}">
<td>{{ forloop.counter }}</td> <!-- ← sequential number -->
<td>{{ entry.id }}</td>
<td>{{ entry.name }}</td>
<td>{{ entry.age }}</td>
<td>{{ entry.email }}</td>
<td>{{ entry.date_joined }}</td>
<td class="actions">
<button class="edit-btn">Edit</button>
<button class="delete-btn">Delete</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endfor %}
</tbody>
</table>
</div>
<!-- Add Entry Popup -->
<div id="add-popup" class="popup">
<!-- Add Popup -->
<div id="add-popup-one" class="popup">
<span class="close-btn">&times;</span>
<h3>Add Entry</h3>
<input type="text" id="add-name" placeholder="Name">
<select id="add-client-id">
{% for client in clients %}
<option value="{{ client.id }}">{{ client.name }}</option>
{% endfor %}
</select>
<input type="number" id="add-age" placeholder="Age">
<input type="email" id="add-email" placeholder="Email">
<button id="save-add">Add</button>
<button id="save-add-one">Add</button>
</div>
<!-- Edit Entry Popup -->
<div id="edit-popup" class="popup">
<!-- Edit Popup -->
<div id="edit-popup-one" class="popup">
<span class="close-btn">&times;</span>
<h3>Edit Entry</h3>
<input type="hidden" id="edit-id">
<input type="text" id="edit-name" placeholder="Name">
<select id="edit-client-id">
{% for client in clients %}
<option value="{{ client.id }}">{{ client.name }}</option>
{% endfor %}
</select>
<input type="number" id="edit-age" placeholder="Age">
<input type="email" id="edit-email" placeholder="Email">
<button id="save-edit">Save</button>
<button id="save-edit-one">Save</button>
</div>
<script>
$(document).ready(function () {
let currentTableId = null; // To track which table is being edited
let currentModelName = null; // To track which model is being used
let currentTableId = 'table-one';
let currentModelName = 'ExcelEntry';
// Open Add Popup for Table 1
$('#add-row-1').on('click', function () {
currentTableId = 'table-1';
currentModelName = 'ExcelEntry'; // Model name for Table 1
$('#add-popup').fadeIn();
$('#add-row-one').on('click', function () {
$('#add-popup-one').fadeIn();
});
// Close Popups
$('.close-btn').on('click', function () {
$('.popup').fadeOut();
});
// Save Add Entry
$('#save-add').on('click', function () {
let name = $('#add-name').val();
// Add
$('#save-add-one').on('click', function () {
let client_id = $('#add-client-id').val();
let age = $('#add-age').val();
let email = $('#add-email').val();
@ -208,7 +201,7 @@
url: `/add-entry/${currentModelName}/`,
method: 'POST',
data: {
'name': name,
'client_id': client_id,
'age': age,
'email': email,
'csrfmiddlewaretoken': '{{ csrf_token }}'
@ -217,40 +210,37 @@
let rowCount = $(`#${currentTableId} tbody tr`).length + 1;
let newRow = `
<tr data-id="${response.id}">
<td>${rowCount}</td> <!-- serial number -->
<td>${rowCount}</td>
<td>${response.id}</td>
<td>${response.name}</td>
<td>${response.client_name}</td>
<td>${response.age}</td>
<td>${response.email}</td>
<td>${response.date_joined}</td>
<td class="actions">
<button class="edit-btn">Edit</button>
<button class="delete-btn">Delete</button>
<button class="edit-btn-one">Edit</button>
<button class="delete-btn-one">Delete</button>
</td>
</tr>
`;
$(`#${currentTableId} tbody`).append(newRow);
$('#add-popup').fadeOut();
$('#add-popup-one').fadeOut();
}
});
});
// Open Edit Popup
$(document).on('click', '.edit-btn', function () {
// Edit
$(document).on('click', '.edit-btn-one', function () {
let row = $(this).closest('tr');
currentTableId = row.closest('table').attr('id'); // Set current table ID
currentModelName = currentTableId === 'table-1' ? 'ExcelEntry' : 'SecondTableEntry'; // Set model name
$('#edit-id').val(row.data('id'));
$('#edit-name').val(row.find('td:eq(2)').text()); // Name is now in column 2
$('#edit-age').val(row.find('td:eq(3)').text()); // Age is now in column 3
$('#edit-email').val(row.find('td:eq(4)').text()); // Email is now in column 4
$('#edit-popup').fadeIn();
$('#edit-client-id').val(row.find('td:eq(2)').text());
$('#edit-age').val(row.find('td:eq(3)').text());
$('#edit-email').val(row.find('td:eq(4)').text());
$('#edit-popup-one').fadeIn();
});
// Save Edit Entry
$('#save-edit').on('click', function () {
$('#save-edit-one').on('click', function () {
let id = $('#edit-id').val();
let name = $('#edit-name').val();
let client_id = $('#edit-client-id').val();
let age = $('#edit-age').val();
let email = $('#edit-email').val();
@ -259,7 +249,7 @@
method: 'POST',
data: {
'id': id,
'name': name,
'client_id': client_id,
'age': age,
'email': email,
'csrfmiddlewaretoken': '{{ csrf_token }}'
@ -270,7 +260,7 @@
row.find('td:eq(2)').text(response.name);
row.find('td:eq(3)').text(response.age);
row.find('td:eq(4)').text(response.email);
$('#edit-popup').fadeOut();
$('#edit-popup-one').fadeOut();
} else {
alert('Failed to update entry: ' + response.message);
}
@ -281,12 +271,10 @@
});
});
// Delete Entry
$(document).on('click', '.delete-btn', function () {
// Delete
$(document).on('click', '.delete-btn-one', function () {
let row = $(this).closest('tr');
let id = row.data('id');
currentTableId = row.closest('table').attr('id'); // Set current table ID
currentModelName = currentTableId === 'table-1' ? 'ExcelEntry' : 'SecondTableEntry'; // Set model name
if (!confirm('Are you sure you want to delete this entry?')) return;
@ -313,4 +301,4 @@
</script>
</body>
</html>
</html>

View File

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Excel-like Table</title>
<title>Helium Output</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css" />
@ -56,11 +56,11 @@
cursor: pointer;
font-size: 14px;
}
.edit-btn {
.edit-btn-two {
background-color: #28a745;
color: white;
}
.delete-btn {
.delete-btn-two {
background-color: #dc3545;
color: white;
}
@ -111,6 +111,15 @@
.add-row-btn:hover {
background-color: #0056b3;
}
.popup select {
display: block;
margin-bottom: 10px;
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
@ -122,22 +131,22 @@
</a>
</div>
<h2>Excel-like Table</h2>
<h2>Helium Output</h2>
<!-- Second Table -->
<div class="table-container">
<button class="add-row-btn" id="add-row-2">Add Row</button>
<table id="table-2">
<button class="add-row-btn" id="add-row-two">Add Row</button>
<table id="table-two">
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Email</th>
<th>Client</th>
<th>Entry 1</th>
<th>Entry 2</th>
<th>Date Joined</th>
<th>Actions</th>
</tr>
@ -147,13 +156,13 @@
<tr data-id="{{ entry.id }}">
<td>{{ forloop.counter }}</td>
<td>{{ entry.id }}</td>
<td>{{ entry.name }}</td>
<td>{{ entry.client.name }}</td>
<td>{{ entry.age }}</td>
<td>{{ entry.email }}</td>
<td>{{ entry.date_joined }}</td>
<td class="actions">
<button class="edit-btn">Edit</button>
<button class="delete-btn">Delete</button>
<button class="edit-btn-two">Edit</button>
<button class="delete-btn-two">Delete</button>
</td>
</tr>
{% endfor %}
@ -163,24 +172,32 @@
</div>
<!-- Add Entry Popup -->
<div id="add-popup" class="popup">
<div id="add-popup-two" class="popup">
<span class="close-btn">&times;</span>
<h3>Add Entry</h3>
<input type="text" id="add-name" placeholder="Name">
<select id="add-client-id">
{% for client in clients %}
<option value="{{ client.id }}">{{ client.name }}</option>
{% endfor %}
</select>
<input type="number" id="add-age" placeholder="Age">
<input type="email" id="add-email" placeholder="Email">
<button id="save-add">Add</button>
<button id="save-add-two">Add</button>
</div>
<!-- Edit Entry Popup -->
<div id="edit-popup" class="popup">
<div id="edit-popup-two" class="popup">
<span class="close-btn">&times;</span>
<h3>Edit Entry</h3>
<input type="hidden" id="edit-id">
<input type="text" id="edit-name" placeholder="Name">
<select id="edit-client-id">
{% for client in clients %}
<option value="{{ client.id }}">{{ client.name }}</option>
{% endfor %}
</select>
<input type="number" id="edit-age" placeholder="Age">
<input type="email" id="edit-email" placeholder="Email">
<button id="save-edit">Save</button>
<button id="save-edit-two">Save</button>
</div>
<script>
@ -189,10 +206,10 @@
let currentModelName = null; // To track which model is being used
// Open Add Popup for Table 2
$('#add-row-2').on('click', function () {
currentTableId = 'table-2';
$('#add-row-two').on('click', function () {
currentTableId = 'table-two';
currentModelName = 'SecondTableEntry'; // Model name for Table 2
$('#add-popup').fadeIn();
$('#add-popup-two').fadeIn();
});
// Close Popups
@ -201,8 +218,8 @@
});
// Save Add Entry
$('#save-add').on('click', function () {
let name = $('#add-name').val();
$('#save-add-two').on('click', function () {
let client_id = $('#add-client-id').val(); // ✅ Correct variable
let age = $('#add-age').val();
let email = $('#add-email').val();
@ -210,49 +227,49 @@
url: `/add-entry/${currentModelName}/`,
method: 'POST',
data: {
'name': name,
'client_id': client_id, // ✅ REPLACE 'name' with this
'age': age,
'email': email,
'csrfmiddlewaretoken': '{{ csrf_token }}'
},
success: function (response) {
let rowCount = $('#table-2 tbody tr').length + 1;
let rowCount = $('#table-two tbody tr').length + 1;
let newRow = `
<tr data-id="${response.id}">
<td>${rowCount}</td> <!-- Serial # -->
<td>${response.id}</td> <!-- ID -->
<td>${response.name}</td> <!-- Name -->
<td>${response.client_name}</td> <!-- Name -->
<td>${response.age}</td> <!-- Age -->
<td>${response.email}</td> <!-- Email -->
<td>${response.date_joined}</td> <!-- Date Joined -->
<td class="actions"> <!-- Actions -->
<button class="edit-btn">Edit</button>
<button class="delete-btn">Delete</button>
<button class="edit-btn-two">Edit</button>
<button class="delete-btn-two">Delete</button>
</td>
</tr>
`;
$('#table-2 tbody').append(newRow);
$('#add-popup').fadeOut();
$(`#${currentTableId} tbody`).append(newRow);
$('#add-popup-two').fadeOut();
}
});
});
// Open Edit Popup
$(document).on('click', '.edit-btn', function () {
$(document).on('click', '.edit-btn-two', function () {
let row = $(this).closest('tr');
currentTableId = row.closest('table').attr('id'); // Set current table ID
currentModelName = currentTableId === 'table-1' ? 'ExcelEntry' : 'SecondTableEntry'; // Set model name
currentModelName = 'SecondTableEntry'; // Set model name
$('#edit-id').val(row.data('id'));
$('#edit-name').val(row.find('td:eq(2)').text()); // Name is now in column 2
$('#edit-client-id').val(row.find('td:eq(2)').text()); // Name is now in column 2
$('#edit-age').val(row.find('td:eq(3)').text()); // Age is now in column 3
$('#edit-email').val(row.find('td:eq(4)').text()); // Email is now in column 4
$('#edit-popup').fadeIn();
$('#edit-popup-two').fadeIn();
});
// Save Edit Entry
$('#save-edit').on('click', function () {
$('#save-edit-two').on('click', function () {
let id = $('#edit-id').val();
let name = $('#edit-name').val();
let client_id = $('#edit-client-id').val();
let age = $('#edit-age').val();
let email = $('#edit-email').val();
@ -261,7 +278,7 @@
method: 'POST',
data: {
'id': id,
'name': name,
'client_id': client_id,
'age': age,
'email': email,
'csrfmiddlewaretoken': '{{ csrf_token }}'
@ -272,7 +289,7 @@
row.find('td:eq(2)').text(response.name);
row.find('td:eq(3)').text(response.age);
row.find('td:eq(4)').text(response.email);
$('#edit-popup').fadeOut();
$('#edit-popup-two').fadeOut();
} else {
alert('Failed to update entry: ' + response.message);
}
@ -284,11 +301,11 @@
});
// Delete Entry
$(document).on('click', '.delete-btn', function () {
$(document).on('click', '.delete-btn-two', function () {
let row = $(this).closest('tr');
let id = row.data('id');
currentTableId = row.closest('table').attr('id'); // Set current table ID
currentModelName = currentTableId === 'table-1' ? 'ExcelEntry' : 'SecondTableEntry'; // Set model name
currentModelName = 'SecondTableEntry'; // Set model name
if (!confirm('Are you sure you want to delete this entry?')) return;

View File

@ -1,6 +1,6 @@
from django.urls import path
from . import views
# Create your URLs here.
urlpatterns = [
path('', views.clients_list, name='clients_list'), # Main page
path('table-one/', views.table_one_view, name='table_one'), # Table One

View File

@ -4,29 +4,43 @@ from django.apps import apps
from datetime import date
from .models import Client
# Clients Page (Now the homepage)
# Clients Page (Main)
def clients_list(request):
clients = Client.objects.all().order_by('id')
return render(request, 'clients_table.html', {'clients': clients})
# Table One View (ExcelEntry)
def table_one_view(request):
entries_table1 = apps.get_model('sheets', 'ExcelEntry').objects.all()
return render(request, 'table_one.html', {'entries_table1': entries_table1})
ExcelEntry = apps.get_model('sheets', 'ExcelEntry')
entries_table1 = ExcelEntry.objects.all()
clients = Client.objects.all()
return render(request, 'table_one.html', {
'entries_table1': entries_table1,
'clients': clients,
})
# Table Two View (SecondTableEntry)
def table_two_view(request):
entries_table2 = apps.get_model('sheets', 'SecondTableEntry').objects.all()
return render(request, 'table_two.html', {'entries_table2': entries_table2})
SecondTableEntry = apps.get_model('sheets', 'SecondTableEntry')
entries_table2 = SecondTableEntry.objects.all()
clients = Client.objects.all()
return render(request, 'table_two.html', {
'entries_table2': entries_table2,
'clients': clients,
})
# Add Entry (Generic for all models)
# Add Entry (Generic)
def add_entry(request, model_name):
if request.method == 'POST':
try:
model = apps.get_model('sheets', model_name)
name = request.POST.get('name', 'New Name')
if model_name.lower() == 'client':
name = request.POST.get('name', 'New Name')
address = request.POST.get('address', '')
entry = model.objects.create(name=name, address=address)
return JsonResponse({
@ -35,11 +49,13 @@ def add_entry(request, model_name):
'address': entry.address,
})
client_id = request.POST.get('client_id')
client = Client.objects.get(id=client_id)
age = int(request.POST.get('age', 0))
email = request.POST.get('email', 'example@email.com')
entry = model.objects.create(
name=name,
client=client,
age=age,
email=email,
date_joined=date.today()
@ -47,7 +63,7 @@ def add_entry(request, model_name):
return JsonResponse({
'id': entry.id,
'name': entry.name,
'client_name': client.name,
'age': entry.age,
'email': entry.email,
'date_joined': entry.date_joined.strftime('%Y-%m-%d'),
@ -58,19 +74,18 @@ def add_entry(request, model_name):
return JsonResponse({'status': 'error', 'message': 'Invalid request'}, status=400)
# Update Entry (Generic for all models)
# Update Entry (Generic)
def update_entry(request, model_name):
if request.method == 'POST':
try:
model = apps.get_model('sheets', model_name)
entry_id = int(request.POST.get('id'))
entry = model.objects.get(id=entry_id)
name = request.POST.get('name')
if model_name.lower() == 'client':
address = request.POST.get('address', '')
entry.name = name
entry.address = address
entry.name = request.POST.get('name')
entry.address = request.POST.get('address', '')
entry.save()
return JsonResponse({
'status': 'success',
@ -79,10 +94,12 @@ def update_entry(request, model_name):
'address': entry.address,
})
client_id = request.POST.get('client_id')
client = Client.objects.get(id=client_id)
age = int(request.POST.get('age'))
email = request.POST.get('email')
entry.name = name
entry.client = client
entry.age = age
entry.email = email
entry.save()
@ -90,7 +107,7 @@ def update_entry(request, model_name):
return JsonResponse({
'status': 'success',
'id': entry.id,
'name': entry.name,
'name': client.name,
'age': entry.age,
'email': entry.email,
'date_joined': entry.date_joined.strftime('%Y-%m-%d'),
@ -103,7 +120,8 @@ def update_entry(request, model_name):
return JsonResponse({'status': 'error', 'message': 'Invalid request'}, status=400)
# Delete Entry (Generic for all models)
# Delete Entry (Generic)
def delete_entry(request, model_name):
if request.method == 'POST':
try: