Allocating items to users

31 views
Skip to first unread message

dtdave

unread,
May 13, 2022, 12:27:48 PM5/13/22
to Django users
I have the following code:
from django.conf import settings
from django.db import models

class AccountManager(models.Model):
    account_manager = models.ForeignKey(
        settings.AUTH_USER_MODEL, on_delete=models.PROTECT, null=True, blank=True
    )

    class Meta:
        verbose_name = 'Account Manager'
        verbose_name_plural = 'Account Managers'

    def __str__(self):
        return str(self.account_manager)
The view for this, effectively a profile, is as follows

from django.contrib.auth import get_user_model
from django.shortcuts import render
from django.views.generic import DetailView
from django.contrib.auth.mixins import LoginRequiredMixin

from .models import AccountManager

User = get_user_model()


class AccountManagerDetailView(LoginRequiredMixin, DetailView):
    model = AccountManager
    template_name = "accountmanagers/dashboard.html"
 
    def get_object(self, *args, **kwargs):
        return self.request.user

And the url:
urlpatterns = [
    path('detail/', views.AccountManagerDetailView.as_view(), name='accountmanagers'),
]
The template then shows the relevant user details but my problem is that I am stuck allocating the clients to the specific account manager. I know that I am missing the point in implementing a queryset and tieing it to that user.
Any help would be appreciated.

Ryan Nowakowski

unread,
May 23, 2022, 10:02:43 AM5/23/22
to Django users
What would you like the relationship between client and account manager
to be? One to one? One to many? Many to many?

- Ryan N
Reply all
Reply to author
Forward
0 new messages