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

Pass a form created with captured url parameters to a generic django view?

This seems like it should be obvious, but the solution is eluding me. Normally I would just write a simple view function which would populate an appropriate form and pass it along to the view, but the solution feels so close .. I have a form. I want…
Seth
  • 45,033
  • 10
  • 85
  • 120
4
votes
1 answer

Django FormView: distinguishing between create and update

I have a mixin for a custom FormView class that simply adds a success message if the save was successful, so: class MessagesMixin(object): def form_valid(self, form): response = super(MessagesMixin, self).form_valid(form) …
ptr
  • 3,292
  • 2
  • 24
  • 48
4
votes
0 answers

Updating a model instance with foreign key through Django generic update view.

I have a django model called "classifieds" which as name suggests is a classified database.Each instance of classifeds will have multiple images attached to it. So created another model named "ClassifiedImage" and associated to "classified" model…
shaytac
  • 3,789
  • 9
  • 36
  • 44
4
votes
1 answer

Django : Can I use CreateView and DeleteView in same form?

I want show two button in same form, first button I want use for delete object, and second button to create an object. For example i want create simple Model like: models.py: class UrlStatus_Proxy(models.Model): urls = models.URLField(u'Site…
4
votes
2 answers

Django: How to call class-based generic views in views.py?

I want to call class-based generic views in views.py Please see my code... urls.py from django.conf.urls import patterns, include, url from crm.views import * urlpatterns = patterns('', (r'^workDailyRecord/$', workDailyRecord), ) and my…
chobo
  • 4,830
  • 5
  • 23
  • 36
4
votes
1 answer

Django Forms for generic relationships. How to include them?

I have a Phone model that is being constantly used by many different models as a generic relationship. I have no idea how to include it in the Create/Update forms for those models… how good or bad of an idea is it to include the extra fields in a…
la_f0ka
  • 1,773
  • 3
  • 23
  • 44
4
votes
1 answer

How to use url pattern named group with generic view?

I'm trying to display blog records for particular author using generic view: urlpatterns = patterns('', url(r'^blog/(?P[\d+])/$', ListView.as_view( queryset=Blog.objects.filter(published=True, author=uid), ),…
Vlad T.
  • 2,568
  • 3
  • 26
  • 40
3
votes
1 answer

How can i get my object id from a generic update views to use in my form in django 1.1

I m using generic view to update object. I m using form : class VehiPrepaClientForm(ModelForm): class Meta: model = VehiPrepa fields = ('date_dem_prepa','carburant','ty_carburant') def clean(self): cleaned_data =…
laurent
  • 660
  • 2
  • 8
  • 19
3
votes
3 answers

Confirming generic FormView POST success back to user with POST data

Using a generic FormView I'd like to reflect something about the POST data that was submitted back to the user, but I'm not sure how best to do this. class MyView(generic.FormView): form_class = MyForm def get_success_url(self): …
danodonovan
  • 19,636
  • 10
  • 70
  • 78
3
votes
1 answer

How to use date based views in Django

It maybe a little naive question but I have been trying to understand how I can use the new Date Based views in django, but without an example, I am at a dead end. What I want to do is to show all my blog entries on a page (with pagination) and in…
Sachin
  • 3,672
  • 9
  • 55
  • 96
3
votes
1 answer

Django auth_view and generic class-based views

Is it safe to code against django's auth_view for password_change or is there any class-based view that I can use? I am converting all my function based views to class based views, but I have coded against django's auth_view that is not class based.
3
votes
1 answer

Multiple Templates in Generic ListView in Django

I have a list of objects that can be seen as a separate page or within another page (though ajax). So, in my templates, I have a "list_template.html" that only has the list itself, which I use when I'm viewing the list within another page and a…
duduklein
  • 10,014
  • 11
  • 44
  • 55
3
votes
1 answer

Can I combine Create and List class based generic views using mixins?

I'm looking for the easiest way to combine List and Create functionally with generic class views. I want to have a page that has an item list and a form to add a new item on the bottom. I thought that mixin architecture would allow to combine…
3
votes
3 answers

Accessing user in Class-based generic views

I'm trying to check if user.is_authenticated() or if user.has_perm() but it seems impossible extending django Class-based genering views. The only method I found where the request appears is get(). class MyDetailView(DetailView): def get(self,…
seler
  • 8,803
  • 4
  • 41
  • 54
3
votes
1 answer

Can't pass 'slug' field into URL via generic class view

I have two models for Publications and Employees: class Publication(models.Model): BOOK_CHAPTER = 1 ARTICLE = 2 PUBLICATION_CHOICES = ( (BOOK_CHAPTER, 'Book chapter'), (ARTICLE, 'Article'), ) publication_type =…