I am a beginner and trying to create a basic college portal.
I am getting NoReverseMatch at /admin/api/student/add/ error when adding students data in django-admin panel.
urls.py
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/',admin.site.urls),
path('api/',include('api.urls')),
]
admin.py
from django.contrib import admin
from .models import Student, Instructor, Course, Enrollment
@admin.register(Student)
class StudentAdmin(admin.ModelAdmin):
list_display = ['std_id', 'firstname', 'lastname', 'date_of_birth', 'cgpa']
@admin.register(Course)
class CourseAdmin(admin.ModelAdmin):
list_display = ['course_id', 'coursename', 'cred_hrs']
@admin.register(Instructor)
class InstructorAdmin(admin.ModelAdmin):
list_display = ['instructor_id', 'instructor_name']
@admin.register(Enrollment)
class EnrollmentAdmin(admin.ModelAdmin):
list_display = ['enrollment_id', 'student', 'course', 'instructor']
models.py
from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator
# Create your models here.
class Student(models.Model):
std_id = models.CharField(max_length=6,primary_key = True, unique=True , editable=False)
firstname = models.CharField(max_length=30)
lastname = models.CharField(max_length=30)
date_of_birth = models.DateField()
cgpa = models.FloatField(
validators=[MinValueValidator(0), MaxValueValidator(4)]
)
class Course(models.Model):
CREDIT_HOURS_CHOICES = [
(1, '1 credit hour'),
(2, '2 credit hours'),
(3, '3 credit hours'),
]
course_id = models.CharField(max_length=6,primary_key = True, unique=True , editable=False)
coursename = models.CharField(max_length=100)
cred_hrs = models.IntegerField(choices=CREDIT_HOURS_CHOICES)
class Instructor(models.Model):
instructor_id = models.CharField(max_length=6,primary_key = True, unique=True , editable=False)
instructor_name = models.CharField(max_length=100)
class Enrollment(models.Model):
enrollment_id = models.AutoField(primary_key=True)
student = models.ForeignKey(Student, on_delete=models.CASCADE)
course = models.ForeignKey(Course, on_delete=models.CASCADE)
instructor = models.ForeignKey(Instructor,on_delete = models.CASCADE)
I am new to this kind of stuff so yeah…
I tried to look up for any mistakes in the code I provided but everything looks kinda fine…
Used chatgpt but no luck
New contributor
Shahab Khanzada is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.