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

Django - use generic views or not?

I was going through quick poll tutorial on the Django site, and the last topic is introduction of generic views. A convenient way to bypass the need of creation of custom views for every URL pattern. This is the main idea as far as I understand: 1)…
Ska
  • 6,658
  • 14
  • 53
  • 74
8
votes
2 answers

How can I make a Generic Class Based Create View for a Model?

What I'm trying to do is Django boilerplate for functional views. Any help here is very much appreciated, as the docs show examples for the template view and list view, but I've found very little for the model-based generic views. Am I missing an…
Lockjaw
  • 1,882
  • 2
  • 16
  • 15
8
votes
1 answer

Django file upload with UpdateView

I tried a minimalistic django implementation of generic views to upload profile pictures. views.py class UpdateProfile(UpdateView): form_class = UpdateUserProfileForm model = UserProfile success_url =…
user1491229
  • 683
  • 1
  • 9
  • 14
8
votes
2 answers

django filtering by user id in Class based ListView

I have a class based ListView of which I would like to filter the objects by the logged in user_id since Item model has a foreign key to settings.AUTH_USER_MODEL class ItemListView(LoginRequiredMixin, StaffRequiredMixin, ListView): model = Item …
8
votes
1 answer

Django-haystack generic SearchView - no results

I'm tryinig to get haystack working with a class-based generic view according to the documentation here. I can get results from a SearchQuerySet in the shell, so the models are being indexed. But I can't get the view to return a result on the…
deixismou
  • 331
  • 2
  • 8
8
votes
2 answers

Django form_valid() and form_invalid() in CreateView not called

I am currently using django's CreateView to post data to the database. Unfortunately, the method where I would like to save and perform custom logic, form_valid() is never called. I read on another stack overflow response that form_invalid() might…
Ryan Brandt
  • 587
  • 1
  • 4
  • 12
8
votes
3 answers

extra context in django generic.listview

So I have two models: Car and Picture. a car may have multiple pictures. Now I want to use a list view to display all the cars along with one picture for each car, can someone tell me how can I do that? Below is my code # models.py class…
JSNoob
  • 1,477
  • 2
  • 18
  • 31
7
votes
2 answers

Django - CreateView - How to declare variable and use it in templates

How do I declare a variable in Django's Createview, so I can use it from its template? For example I want to use {{ place_slug }} in the template. I pass that from urls.py like below: urls.py: urlpatterns = patterns('', …
DavidL
  • 1,260
  • 2
  • 17
  • 35
7
votes
2 answers

Django Class-Based Generic Views and ModelForms

Like much documentation on generic views in Django, I can't find docs that explicitly describe how to use the new Class-Based Generic Views with Django Forms. How is it done?
7
votes
1 answer

Using class based generic view DetailView with a ModelForm reveals a bug - how to proceed?

I've been impressed how rapidly a functional website can go together with generic views in the tutorials. Also, the workflow for form processing is nice. I used the ModelForm helper class to create a form from a model I made and was delighted to see…
kd4ttc
  • 1,075
  • 1
  • 10
  • 28
7
votes
4 answers

Django Generic View - Access to request

I am using django generic views, how do I get access to the request in my template. URLs: file_objects = { 'queryset' : File.objects.filter(is_good=True), } urlpatterns = patterns('', (r'^files/',…
Mark
  • 2,522
  • 5
  • 36
  • 42
7
votes
1 answer

Filter non-existing GenericForeignKey objects in Django queryset

I have a simple model with a generic foreign key: class Generic(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') I…
7
votes
1 answer

django: DetailView: self.object raises an error when called from the method post, but it does work when called from the method get_context_data

I created a class that inherits from DetailView, and I overrided the methods get_context_data and post. What it seems weird as mentioned in the title, is that I can call self.object from get_context_data but I can't from post so I had to use…
smarber
  • 4,829
  • 7
  • 37
  • 78
6
votes
1 answer

DRF - How to get created object in CreateAPIView

My goal very much resembles to what has been asked in this question but from the perspective of DRF, rather than forms. So basically the question is, how can I get the newly created object in the following code…
Edgar Navasardyan
  • 4,261
  • 8
  • 58
  • 121
6
votes
1 answer

Accessing a context object in a Django class-based generic view

I'm using a DetailView to view a Project object, and I would like to be able to access the Project object being viewed in order to pass it to a decorator, something like this: class ProjectDetailView(DetailView): context_object_name = "project" …
1 2
3
37 38