django-generic-views

Django file upload with UpdateView

非 Y 不嫁゛ 提交于 2019-12-01 06:01:17
问题 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 = reverse_lazy('show_profile') models.py class UserProfile(models.Model): user = models.OneToOneField(User) website = models.URLField(blank=True) picture = models.ImageField(upload_to='user/img/%Y-%m-%d/', blank=True) forms.py class UpdateUserProfileForm(forms.ModelForm): class Meta: model =

Django - Generic View Subclassed - url Parameters

空扰寡人 提交于 2019-12-01 04:48:20
问题 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<pk>\d+)$', VideoFileDetailView.as_view()), #... #view class VideoFileDetailView(DetailView): model = VideoFile def get_context_data(self, **kwargs): context = super(VideoFileDetailView, self).get_context_data(**kwargs) # context['rates'] = VideoRate.objects.filter(video=11, user=1) return

How to access RequestContext in class-based generic views?

元气小坏坏 提交于 2019-11-30 22:02:35
问题 I have this path in my urls.py: archive_index_dict = { 'queryset': News.objects.filter(show=True), 'date_field': 'date', 'template_object_name': 'object_list', } ... url(r'^$', 'django.views.generic.date_based.archive_index', archive_index_dict, name='news_archive_index' ), Now I want to detect in template if a page is current (this is for menu styling). Neither {{ request.path }} nor {{ request.get_full_path }} work in template. What should I use instead? SOLUTION To get request available in

how to send success message if we use django generic views

删除回忆录丶 提交于 2019-11-30 11:56:04
I am new to django (1.2.4). I have created some crud with generic views. But How can I show something like "The student was added successfully" when student is created using django's messaging framework? As far as I know, there isn't a straightforward way of doing this using traditional generic views. I've always felt that the documentation on generic views was pretty lacking and so never used them. In theory you could use a decorator by making the assumption that a redirect meant a successful submission. So you could write something like this (none of this code has been tested): urls.py : try

Use get_queryset() method or set queryset variable?

眉间皱痕 提交于 2019-11-29 20:20:27
These two pieces of code are identical at the first blush: class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'latest_poll_list' queryset = Poll.active.order_by('-pub_date')[:5] and class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'latest_poll_list' def get_queryset(self): return Poll.active.order_by('-pub_date')[:5] Is there any difference between them? And if it is: What approach is better? Or when setting queryset variable is better than override the get_queryset method? And vice versa. In your example,

how to send success message if we use django generic views

余生长醉 提交于 2019-11-29 17:08:06
问题 I am new to django (1.2.4). I have created some crud with generic views. But How can I show something like "The student was added successfully" when student is created using django's messaging framework? 回答1: As far as I know, there isn't a straightforward way of doing this using traditional generic views. I've always felt that the documentation on generic views was pretty lacking and so never used them. In theory you could use a decorator by making the assumption that a redirect meant a

Excluding fields in generic CRUD views

☆樱花仙子☆ 提交于 2019-11-29 17:05:18
I have a model named Domain which looks like this: class Domain(models.Model): """ Model for storing the company domains """ user = models.ForeignKey( User ) host = models.CharField( null=False, verbose_name="Host", max_length=128, unique=True ) I'd like to use Django's generic views for doing CRUD operations on this. There is one field in this model that needs user input but the foreign key field doesn't need any user input. How can I exclude that field from the form that my generic view generates but assign it the value of the current authenticated user. Thanks. Have a look at Russel's

Django/python: 'function' object has no attribute 'as_view'

只愿长相守 提交于 2019-11-29 12:43:18
问题 I am trying to create a list_view for a model queryset. When running my server, it returns : attribute error - 'function' object has no attribute 'as_view'. I would appreciate helping me in solve this. Here's my code: Views.py: @login_required class live_bids(ListView): model = Post template_name = 'loggedin_load/live_bids.html' def get_queryset(self): return Post.objects.all().prefetch_related('bids').filter(user=self.request.user) urls.py: url(r'^live_bids/$', live_bids.as_view()), 回答1: You

Curious about get_form_kwargs in FormView

元气小坏坏 提交于 2019-11-29 11:19:49
问题 I was having trouble with FormView recently and found that the way to go about doing it was to use get_form_kwargs. Here is my code: class InternalResetPasswordView(FormView): template_name = 'reset_password.html' form_class = forms.InternalPasswordResetForm # success_message = "Password was reset successfully" # To get request object # http://notesondjango.wordpress.com/2012/12/18/modelform-formview-and-the-request-object/ # https://stackoverflow.com/questions/13383381/show-message-after

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

本小妞迷上赌 提交于 2019-11-29 10:50:29
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 that so much functionality came together. When I used the generic list_detail.object_detail I was disappointed that all that I could display were fields individually. I knew the ModelForm class contained information for rendering, so I wanted to use the ModelForm with a generic view. I was asking around on stackoverflow to get some direction, and