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
5
votes
3 answers

Diference between get_context_data and queryset in Django generic views?

What is the difference between get_context_data and queryset in Django generic views? They seem to do the same thing?
Bootstrap4
  • 3,671
  • 4
  • 13
  • 17
5
votes
3 answers

Django Generic View UpdateView redirect URL with updated slug

This is my updateview which is called by a URL with slug field, e.g. /mymodel/update// MyModel have two fields, name and slug. The slug field is automatically generated from MyModel.name. If the user update it, a…
thinkdeep
  • 945
  • 1
  • 14
  • 32
5
votes
3 answers

Django - Pass model name as parameter to generic view

Let's say I have some Models that inherit from a base class, Animal. I can use generic views and route Cat/12 to a detail view and Dod/10 to the same detail view with a different context. But I would like to get the Model name from the url so that I…
Rob L
  • 3,634
  • 2
  • 19
  • 38
5
votes
2 answers

'Role' object has no attribute '__name__'

I am trying to implement role based permission into my application. I have a decorator role_required into which I can pass a set of user roles and only those user with that role can access that view. I have properly assigned roles to the user but,…
Bithin
  • 409
  • 1
  • 7
  • 16
4
votes
1 answer

django how to loop through the context object passed back by a generic detailview?

I'm using a generic DetailView to display a project object. Can I loop through the fields somehow in my template or do I have to place every field. url(r'^(?P[-\w]+)/$', DetailView.as_view(model=Project, …
darren
  • 18,845
  • 17
  • 60
  • 79
4
votes
2 answers

Django - Generic View Subclassed - url Parameters

I need to display a detail page for a video with some other data. For that I use DetailView that I have overridden to add some variables to the context. Here are the code parts: #urlconf #... (r'viewtube/(?P\d+)$',…
Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307
4
votes
3 answers

How to specify lookup_field in django

I'm going to use UpdateAPIView in django. When I completed the view and ran the server, the following error occurred. Expected view updateViewSet to be called with a URL keyword argument named "pk". Fix your URL conf, or set the `.lookup_field`…
4
votes
2 answers

how to override 'get_queryset()' in Django

I'm going to use the generic view in django. I defined the serializer_class and override the get_queryset() method, but there is an error telling me to override the get_queryset() method. I wonder how my override method is wrong, and what I have to…
4
votes
1 answer

How to add data to context object in DetailView?

I need to write a DetailView in Django. I achieved this functionality. However, I need to add some more data along with the context object. How will I achieve this. My generic view is: class AppDetailsView(generic.DetailView): model =…
deltaforce
  • 524
  • 1
  • 8
  • 25
4
votes
1 answer

success_url for Django LoginView?

High level question: Can I use the success_url attribute to change to where a view inheriting from Django's LoginView will redirect? I have a login view that looks something like the below (ignoring import statements): class MyLoginView(LoginView): …
cmanbst
  • 179
  • 3
  • 13
4
votes
1 answer

Override response of POST in Django Rest Framework

I'm using Django Rest Framework's Generics (generics.ListCreateAPIView), when I make a POST request I get a response of Http code (200/400/..etc.) and a JSON showing the posted data, I need to know how can I override the response to get a custom…
P. Naoum
  • 457
  • 5
  • 14
4
votes
1 answer

Django Rest Framework Serialization error in ListAPIView

I am getting below error Error -- 'many' is an invalid keyword argument for this function" In ListAPIView while serializing a object. class UserSerializer(serializers.ModelSerializer): class Meta: model = User fields = ('id',…
Naresh
  • 1,842
  • 2
  • 24
  • 36
4
votes
1 answer

Django IntegrityError at /new null value in column "owner_id" violates not-null constraint

I'm trying to track the user that created an object using a CreateView and I'm doing it exactly like it's done in documentation (https://docs.djangoproject.com/en/dev/topics/class-based-views/generic-editing/, Models and request.user) except I don't…
4
votes
1 answer

"name 'django' not defined" error when using the generic login view?

I'm am trying to use the generic login view provided by django and this is my urls.py: url(r'^login/$', django.contrib.auth.views.login), When I run the server and go to 127.0.0.1 it gives me a NameError at / saying name 'django' is not…
SilentDev
  • 20,997
  • 28
  • 111
  • 214
4
votes
4 answers

Django: paginated ListView database performance

I have a ListView with pagination: class StoriesListView(ListView): model = Story paginate_by = 20 def get_queryset(self): return Story.objects.all().order_by('-updated_at') I have 1000 Story objects in the database. What…
netimen
  • 4,199
  • 6
  • 41
  • 65