I'm building a ticketing system using the django framework. Whenever a ticket is filled out and submitted, the support group will go into the support app and see the information on what ticket number, customer name, summary, date created, etc. The ticket number is a link to the details of that ticket. What I would like to do is, whenever a user clicks that link, the ticket is automatically assigned to that user. This helps keeps users from being able to pick and choose which tickets they want to do. The way I have it now is whoever updates the ticket to change the status of the ticket, that person is assigned. I feel my options here with django are limited so if you've got any JS ideas, please feel free to share.
Ticket detail view
@group_required('Support')
def ticket_detail(request, pk):
object = get_object_or_404(Ticket, id=pk)
context = {
'object': object,
}
return render(request, 'support/ticket_detail.html', context)
Model
class TicketStatus(models.Model):
name = models.CharField(max_length=25)
def __str__(self):
return self.name
class Ticket(models.Model):
name = models.CharField(max_length=20)
email = models.EmailField()
phone_num = models.CharField(max_length=11)
property = models.CharField(max_length=30, blank=True)
location = models.CharField(max_length=50, blank=True)
summary = models.CharField(max_length=50)
details = models.TextField()
status = models.ForeignKey(TicketStatus, null=True, blank=True, default=1, on_delete=models.CASCADE)
image = models.ImageField(upload_to = 'support/images', blank=True, null=True)
notes = models.TextField(blank=True, null=True)
date_created = models.DateTimeField('date created', auto_now_add=True)
date_updated = models.DateTimeField('date updated', auto_now_add=True)
updated_by = models.ForeignKey(User, on_delete=models.SET_NULL, blank=True, null=True, related_name='up_ticket')
CodePudding user response:
Assuming that you refering to updated_by field of Ticket model you need to add this to your view function:
@group_required('Support')
def ticket_detail(request, pk):
object = get_object_or_404(Ticket, id=pk)
if not object.updated_by:
object.updated_by = request.user
object.save()
context = {
'object': object,
}
return render(request, 'support/ticket_detail.html', context)
This way first user who click link will be assigned to ticket. So user click link, in detail view he is assign to this ticket and after that view return ticket detail page