I have a detail view
from django.shortcuts import get_object_or_404
class Dashboard (AdminStaffRequiredMixin, LoginRequiredMixin, ListView):
model = User
template_name = 'SCHUK/Dashboard.html'
context_object_name = 'Dashboard'
def ansicht(request, pk):
user = get_object_or_404(User, pk=pk)
return render(request, 'SCHUK/Ansicht.html', context={'user': user})
class Ansicht(AdminStaffRequiredMixin, LoginRequiredMixin, DetailView):
model = User
template_name = 'SCHUK/Ansicht.html'
context_object_name = 'Ansicht'
so far so amezin. My genius idea is to view user data by their username. all my models are bound to the user model
class SchulverzeichnisTabelle(models.Model):
Benutzer = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
Konto = models.IntegerField(blank=True, null=True)
S_Form = models.CharField(max_length=20, blank=True, null=True)
Schulname = models.CharField(max_length=150, blank=True, null=True)
etc
but now I have a problems CRUD the user data as staff user. It works but it redirects the staff not the right view
class SVAVerwaltung(LoginRequiredMixin, UpdateView):
model = SchulverzeichnisTabelle
fields = ['Konto', 'S_Form',
'Schulname', 'SAB',
'GL', 'Zuege',
'Teilstandort', 'IH',
'SSt_OGS', 'OGS_Grp',
'VK', 'Z_SW',
'Z_besG', 'U_Ausf',
'U_Org', 'Schulleitung_Vorname',
'Schulleitung_Nachname',
'Lehrer_FK', 'GL_Lehrer_FK']
template_name = 'SCHUK/SVAVerwaltung.html'
context_object_name = 'SVAVerwaltung'
def get_absolute_url(self):
return reverse('Ansicht', args=[str(self.id)])
My goal is to have two user groups, normal and staff. normal view their own data and can only edit it, while staff can view user data and CRUD it not only edit.
Is it somehow possible to get the detailview url to reverse from the updateview. It would also be fine if it just redirect to previous url or even a javascript timed event or regular reverse with a bit kwargs magic or something
I can reverse to a static url but thats not so user friendly.
Also if you have other idea how to implement my user view and staff user view thing I would also love to read it.
I even tried the whole approach over htmx, and that redirects to the right url but shows empty page I guess bc it redirects to staff pk and not detailview pk.
Anyways, is it possible to updateview a set from something like in the template I can display a _set but is it possible to somehow update the _set cuz that would solve everything