Comment model not attached to ticket model

Creating a separate comments app for ticket app. My issue is that when I create and submit my comment on a particle ticket, it creates its own new page of tickets instead of being attached to original ticket. I think the issue has to do with my urls.py file and I feel like i'm close to solving this but i’m not sure how to proceed.

Here is my comment models.py

from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
from tickets.models import Ticket

class Comment(models.Model):
    ticket = models.ForeignKey(Ticket, related_name='comments', on_delete=models.CASCADE, 
             null=True)
    title = models.CharField(max_length=20)
    content = models.TextField()
    date_posted = models.DateTimeField(default=timezone.now)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    
    def __str__(self):
        return self.title
    
    def get_absolute_url(self):
        return reverse('tickets:ticket-detail', kwargs={'pk': self.pk})

Here is my ticket models.py

from django.db import models

from django.utils import timezone

from django.contrib.auth.models import User

from django.urls import reverse

from users.models import Profile

class Ticket(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()
    date_posted = models.DateTimeField(default=timezone.now)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    assignee = models.ForeignKey(Profile, on_delete=models.SET_NULL, blank=True, null=True)
    status = models.BooleanField(choices=MARKED, default=True)
    priority = models.TextField(choices=PRIORITIES, default='None', max_length=10)
    label = models.CharField(choices=TYPES, default='Misc', max_length=100)
    
    
    def __str__(self):
        return self.title
    
    def get_absolute_url(self):
        return reverse('ticket-detail', kwargs={'pk': self.pk})

Here is the main urls.py

from django.conf import settings
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static

app_name = 'tickets'

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('users.urls')),
    path('', include(('tickets.urls', 'tickets'), namespace='tickets')),
    path('', include('tickets.urls')),
    path('', include('comments.urls')),
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Here is the ticket urls.py

from django.conf import settings
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static

app_name = 'tickets'

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('users.urls')),
    path('', include(('tickets.urls', 'tickets'), namespace='tickets')),
    path('', include('tickets.urls')),
    path('', include('comments.urls')),
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Here is my comments urls.py

from django.urls import include, path
from .views import (
    CommentListView,
    CommentCreateView,
    CommentUpdateView,
    CommentDeleteView,
)

urlpatterns = [
    path('tickets/<int:pk>/', CommentListView.as_view(), name='ticket-detail'),
    path('tickets/<int:pk>/comments/new/', CommentCreateView.as_view(), name='comment-create'),
    path('tickets/comments/<int:pk>/update/', CommentUpdateView.as_view(), name='comment-update'),
    path('tickets/comments/<int:pk>/delete/', CommentDeleteView.as_view(), name='comment-delete'),
]
Back to Top