Skip to content

Commit

Permalink
"Updated admin panel views and templates to handle form errors and ad…
Browse files Browse the repository at this point in the history
…ded error printing for debugging"
  • Loading branch information
NexusGKSoftwares committed Nov 26, 2024
1 parent f723df8 commit 83e1a62
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
Binary file modified admin_panel/__pycache__/views.cpython-310.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 5.1.3 on 2024-11-26 19:12

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('admin_panel', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='project',
options={},
),
migrations.RemoveField(
model_name='project',
name='created_at',
),
migrations.RemoveField(
model_name='project',
name='updated_at',
),
migrations.AlterField(
model_name='project',
name='end_date',
field=models.DateField(default=datetime.date(2024, 1, 1)),
preserve_default=False,
),
migrations.AlterField(
model_name='project',
name='name',
field=models.CharField(max_length=255),
),
migrations.AlterField(
model_name='project',
name='status',
field=models.CharField(max_length=100),
),
]
Binary file not shown.
14 changes: 12 additions & 2 deletions admin_panel/templates/admin_panel/add_project.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ <h4>
<div class="card-body">
<form method="POST">
{% csrf_token %}
{{ form.as_p }} <!-- Render form fields -->
<button type="submit" class="btn btn-success">Save Project</button>
{{ form.as_p }}
{% if form.errors %}
<ul>
{% for field in form %}
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
{% endfor %}
</ul>
{% endif %}
<button type="submit" class="btn btn-primary">Save Project</button>
</form>

</div>
</div>
</div>
Expand Down
9 changes: 4 additions & 5 deletions admin_panel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,12 @@ def add_project(request):
if request.method == 'POST':
form = ProjectForm(request.POST)
if form.is_valid():
form.save() # Save the form data to the database
return redirect('project_management') # Redirect to the project management page after saving
print("Form is valid, saving project")
form.save()
return redirect('project_management')
else:
# If the form is not valid, return the same page with form errors
return render(request, 'admin_panel/add_project.html', {'form': form})
print("Form errors: ", form.errors) # Print out form errors
else:
# For GET requests, show an empty form
form = ProjectForm()
return render(request, 'admin_panel/add_project.html', {'form': form})

Expand Down
Binary file modified db.sqlite3
Binary file not shown.

0 comments on commit 83e1a62

Please sign in to comment.