I am using Django-Cookiecutter which uses Django-Allauth to handle all the authentication and there is one App installed called user which handles everything related to users like sign-up, sign-out etc.
I am sharing the models.py file for users
@python_2_unicode_compatible
class User(AbstractUser):
# First Name and Last Name do not cover name patterns
# around the globe.
name = models.CharField(_('Name of User'), blank=True, max_length=255)
def __str__(self):
return self.username
def get_absolute_url(self):
return reverse('users:detail', kwargs={'username': self.username})
Now that I have added my new App say Course and my models.py is
class Course(models.Model):
name = models.CharField(max_length=30)
description = models.CharField(max_length=100)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse("details:assess", kwargs={"id": self.id})
I have also defined my views.py as
@login_required
def course_list(request):
queryset = queryset = Course.objects.all()
print("query set value is", queryset)
context = {
"object_list" :queryset,
}
return render(request, "course_details/Course_details.html", context)
Is there any way I can reference(Foreign key) User App to my Course App so that each user has their own Course assigned to it.
one of the possible ways is to filter objects on the basis of the user and pass it to the template
I can't figure it out that how to map users and course in order to get the list of course which is assigned to the particular user.