Questions tagged [django-generic-views]

Questions about Django’s built-in generic views, which helps you to avoid repeating common code patterns in every project.

Questions about Django’s built-in generic views, which helps you to avoid repeating common code patterns in every project.

568 questions
3
votes
1 answer

lookup_field Return None In Django get_queryset

I have a class extend with GenericAPIView , I Can access to the lookup_field in my functions, but I can't use it in the queryset function. class SellerItemAPIView(GenericAPIView, ListModelMixin): serializer_class = ShopItemSerializer …
Ali Rn
  • 1,114
  • 8
  • 19
3
votes
2 answers

django.template.exceptions.TemplateDoesNotExist: registration/login.html

here's my files: views.py from django.shortcuts import render from django.urls import reverse_lazy from . import forms from django.views.generic import CreateView from django.views.generic import TemplateView class…
lcasdas
  • 33
  • 1
  • 5
3
votes
1 answer

Limit queryset in generic views to objects with request.user as foreign key

I've had to add a method to just about UpdateView, DetailView, ListView, and DeleteView class in views.py to limit the queryset to only return objects that the logged in user is allowed to see (which in my case, means they are the foreignkey user on…
Brenden
  • 8,264
  • 14
  • 48
  • 78
3
votes
4 answers

Django Rest Framework - GenericViewSet with Authentication/Permission decorator

Currently i have a simple rest setup for a single entity, you can create an object and you can retrieve it by the id. "POST" requires authentication/permission, "RETRIEVE" requires no authentication/permission. settings.py (requires global…
3
votes
1 answer

How to update a single field in a model using UpdateAPIView from Djangorestframework?

I'm learning generic views and creating some APIs. How can I update the field: mobile from Model:Contacts? I want to get the user id from URL (mobile/update/user_id) But while creating the queryset it's not working. I want to do something like the…
3
votes
1 answer

Help with django date based generic views

I am using date based generic views for the first time. I have gotten the archive page to work, but for some reason when I create a link to the detail page using get_absolute_url method, the archive page just reloads. Any insight will be helpful,…
3
votes
2 answers

using generic createapiview and updateapiview in the same view in django restframework

Iam trying to find out if it is possible to post and patch in the same view using the generic api method in Django rest framework. I dont think there is any generic class that allows create and update altogether, can anyone tell me if the below…
skidwa
  • 103
  • 3
  • 11
3
votes
1 answer

How to get and display all child objects in parent serializer in DRF

I have 3 different serializers for 3 different views of parent as well as child object. The views are CreateAPIView, ListAPIView, RetrieveAPIView. So my CreateAPIView has one serializer for creating an object, ListAPIView has one serializer for…
3
votes
1 answer

unable to shift pages from homepage to about page

I am trying to create a small web application with django and I am a novice in this I am trying to create a homepage and a about button on homepage that reloads the page to about page This is my index.html …
3
votes
1 answer

I would like to add condition to Django DetailView

I am using Django Generic view, DetailView. But I'd like to block users to access to detail post who did not email_confirmed yet. I have a email_confirmed field in User model. My code is : @method_decorator(login_required(login_url='/login/'),…
HS Park
  • 63
  • 8
3
votes
2 answers

Ajax views with django

I'm working on a pretty big project right now where every view should be accessible via a normal request and an ajax request via the same url. I'm looking for ideas on how to create a small framework to handle this in a very generic way. Depending…
Bernhard Vallant
  • 49,468
  • 20
  • 120
  • 148
3
votes
1 answer

Save formset in an UpdateView

I have the models Entry and Meaning below with many-to-many relation. I need to create an update form/view to edit Entry and Meaning objects at the same time. I have also to be able to add more Meaning objects to an Entry object while editing it. I…
msampaio
  • 3,394
  • 6
  • 33
  • 53
3
votes
1 answer

What generic view should be used to create friend request in drf?

I am building a drf backend api for my android app. I need the API to be able to send friend requests to the relevant users from a user. To do this I am using the django-friendship library. In their documentation they say: Create a friendship…
Tom Finet
  • 2,056
  • 6
  • 30
  • 54
3
votes
1 answer

Django Update/Delete view. Handling user permissions

models.py class Punch(models.Model): ro_number = models.IntegerField() flag = models.FloatField(max_length=10) actual = models.FloatField(max_length=10) description = models.CharField(max_length=100, blank=True) user =…
3
votes
2 answers

Django Generic Views :How does DetailView automatically provides the variable to the template ??

In the following code, How does the template details.html knows that album is passed to it by views.py although we have never returned or defined any context_object_name in DetailsView class in views.py. Please explain how are the various things…
lordzuko
  • 773
  • 10
  • 22