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
0
votes
1 answer

Dynamic get_absolute_url using url query parameters

Big picture: I'd like my reverse method in get_absolute_url (see below) to return a url with a query parameter appended to it at the end, e.g. ?foo=bar. Further, I'd like bar to be specified by the POST request that triggered the call to…
0
votes
1 answer

Django: path doesn't find the right primary key in url path

I'm using django2 and I get an error when I access this url: http://127.0.0.1:8000/hotes/12/access/7/update I get an error 404 "None access object was found" To make a long story short: I want to update an object linked to another. To do so, I have…
0
votes
2 answers

Django generic views DeleteView removes the unexpected object

I have created DeleteView for my 'Album' model, but it's now working as expected. Here is my scripts: urls.py from django.conf.urls import url from . import views urlpatterns = [ url(r'^albums/create/$', views.AlbumCreateView.as_view(),…
Elgin Cahangirov
  • 1,932
  • 4
  • 24
  • 45
0
votes
0 answers

404 error when filtering URL for key arguments with django rest framework generic views

Basically I'm following a tutorial on how to filter for results through url regular expressions for my rest api. I'm looking to go to /api/v1/users/1/goals to get a list of the goals associated with a user. I've scoured the django rest framework…
Efie
  • 1,430
  • 2
  • 14
  • 34
0
votes
2 answers

How to pass the logged in user to direct_to_template?

I'm using direct_to_template for a url but I need the logged in user to display the page. How do I pass it to direct_to_template?
john2x
  • 22,546
  • 16
  • 57
  • 95
0
votes
1 answer

Controlling PolymorphicModel classed object as model in Generic view

I have a PolymorphicModel class named Vehicle, and I derived two class from this: Car and Truck. I use UpdateView to update but it's getting vehicle_id from vehicle_list randomly. And I have to control which type of vehicle is this model. But I…
0
votes
1 answer

How to modify the author choices field in my generic CreateView with authors(fk) only from the current user?

This is my code, i have read the documentations and it seems this method is the right way, i get no errors but i see no results. Can somebody help me in what i am doing wrong? class BookCreate(LoginRequiredMixin, CreateView): model = Book …
0
votes
1 answer

Calling some functions if Generic View is success

I use generic views/class-based views in my project and I want to call some functions if view is done successfully. I use for this def get_success_url() method. But I can't reach the model in that function. How can I get rid of this, or are there…
0
votes
1 answer

generic view does not return any values

I am a beginner in django, and its version is 1.11.6 ,as well as the python version I use is 3.6. I am studying generic view, generic.ListViewdoes not return any values. views.py class IndexView(generic.ListView): template_name =…
0
votes
1 answer

Django: How to return with context from UpdateView (CBV)?

The following view works as expected class BrandEditView(PermissionRequiredMixin ,generic.UpdateView): permission_required = 'change_brand' template_name = 'brand_update_form.pug' model = Brand fields = ['name'] def…
0
votes
1 answer

File Upload fails using ModelForm - no error messages though

I'm using ModelForms with the generic editing views (create, update, delete). One of my aims in this exercise is to get to know some frameworks (Django + Bootstrap + a plugin (e.g. PDF.js)) and use as little custom code as possible. I can create a…
Atcrank
  • 439
  • 3
  • 11
0
votes
1 answer

KeyError: 'manager' in django get_initial

I working on FormView, and I need to set initial from another object, an example in my case we use Question model to set an initial for QuestionSuggestedEditsForm. But we got an error when updating the initial dict. 1.…
binpy
  • 3,994
  • 3
  • 17
  • 54
0
votes
1 answer

Django generic view - clarification on extra_context property - github vs installed source

So i was digging in Django's source codes and came across these two: views.generic.list.py and views.generic.base.py so this is line 26 in base.py in ContextMixin's get_context_data method if self.extra_context is not None: …
Ali Ameli
  • 1
  • 2
0
votes
2 answers

django rest framework global pagination not working with ListCreateAPIView

I have the following in my settings.py REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', 'PAGE_SIZE': 50 } urls.py url(r'^dashboard/users$', views.UserList.as_view()), And the View…
0
votes
2 answers

Django Generic Views Usage

I just imported generic views successfully and here comes the problem when I want to use them in views the server just gives an error directed to "." (period) in generic.ListView... Here is the code I am currently working on. def…