django-views

Django ModelChoiceField drop down box custom population

拜拜、爱过 提交于 2020-01-13 18:15:09
问题 I have a dropdown box that is being populated by a filtered list of objects from a model "Options". Currently, the dropdown list displays the names of each option. How would I get it to display another attribute from the same table? self.fields['name'] = forms.ModelChoiceField(queryset = Options.objects.filter(option_type = s), label = field_label, required=False) Quick example: drop down box currently displays the names of the cars: "Camero, Nissan, Honda" How would I get it to display the

Django won't serve static files while using development server

巧了我就是萌 提交于 2020-01-13 12:17:30
问题 I just started a new development server for a website I am working on and I can't seem to get the Django development server to serve the static files I have for CSS and other things. The CSS for the admin site loads fine. I am running it in a virtualenv sandbox. In settings.py I've messed around with MEDIA_ROOT and MEDIA_URL. So far for MEDIA_ROOT I've tried. MEDIA_ROOT = '/home/wluw/wluw/wluw/media' and MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'media') I changed my ADMIN_MEDIA

django request.POST contains <could not parse>

一笑奈何 提交于 2020-01-13 10:49:27
问题 I am having a django form to get the username,password. when the user posts data, i see that the post dictionary contains the following(traceback), Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py", line 111, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/usr/lib/python2.4/site-packages/django/views/decorators/csrf.py", line 39, in wrapped_view resp = view_func(*args, **kwargs) File "/usr/lib/python2

Django Cart and Item Model - getting quantity to update

拥有回忆 提交于 2020-01-13 07:25:21
问题 I am working on a Django cart application. I have two models Cart and Item. I am trying to get the quantity to update when an Item is added to the basket but cant get the views to work properly. I am having problems getting item_obj assignment to work - do I need to do anything with the model manager here? Any help is really appreciated. Models.py class Cart(models.Model): user = models.ForeignKey(User, null=True, blank=True) products = models.ManyToManyField(Product, blank=True) total =

Django Cart and Item Model - getting quantity to update

ぐ巨炮叔叔 提交于 2020-01-13 07:24:13
问题 I am working on a Django cart application. I have two models Cart and Item. I am trying to get the quantity to update when an Item is added to the basket but cant get the views to work properly. I am having problems getting item_obj assignment to work - do I need to do anything with the model manager here? Any help is really appreciated. Models.py class Cart(models.Model): user = models.ForeignKey(User, null=True, blank=True) products = models.ManyToManyField(Product, blank=True) total =

How to pass parameters to django generic views

限于喜欢 提交于 2020-01-13 07:16:49
问题 I would like to pass a number to my generic view (DetailView) to get one object Here is my code Urlpattern (r'^newreportview/(?P<number>\w+)/$', NewReportView.as_view()), View Class class NewReportView(DetailView): template_name = "report/newreportview.html" context_object_name = "newreportview" def get_queryset(self): task= get_object_or_404(MyTask,applicationnnumber=self.args[0]) return task I guess something is wrong in this line name = get_object_or_404(MyTask,applicationnnumber=self.args

Django view getting called twice (double GET request)

北慕城南 提交于 2020-01-13 05:56:52
问题 I'm creating a classifieds website in Django. A single view function handles global listings, city-wise listings, barter-only global listings and barter-only city-wise listings. This view is called ads . The url patterns are written in the following order (note that each has a unique name although it's tied to the same ads view): urlpatterns = patterns('', url(r'^buy_and_sell/$', ads,name='classified_listing'), url(r'^buy_and_sell/barter/$', ads,name='barter_classified_listing'), url(r'^buy

Django REST Framework: 'BasePermissionMetaclass' object is not iterable

落爺英雄遲暮 提交于 2020-01-12 19:10:08
问题 Python/Django n00b moving over from javascript. Trying to add an API endpoint using Django REST Framework which I'm hoping will ultimately be able to update a User with the body of a PATCH request, but for now I just want it to not throw a 500 error. I've added this to urlpatterns: url(r'update/$', views.UpdateView.as_view(), name="update_user"), And that should bring in this view: from django.contrib.auth.models import User from rest_framework.generics import UpdateAPIView from .serializers

Django REST Framework: 'BasePermissionMetaclass' object is not iterable

心已入冬 提交于 2020-01-12 19:09:51
问题 Python/Django n00b moving over from javascript. Trying to add an API endpoint using Django REST Framework which I'm hoping will ultimately be able to update a User with the body of a PATCH request, but for now I just want it to not throw a 500 error. I've added this to urlpatterns: url(r'update/$', views.UpdateView.as_view(), name="update_user"), And that should bring in this view: from django.contrib.auth.models import User from rest_framework.generics import UpdateAPIView from .serializers

How to raise a error inside form_valid method of a CreateView

若如初见. 提交于 2020-01-12 15:47:08
问题 In a Django project, I have a view (cloud), type: CreateView. This view has a inlineformset_factory. It works. But, if i submit the form with a error (look at "messages.error" below), the page is redirected to project.get_absolute_url(). The problem is: the form content back empty. I know thats because the HttpResponseRedirect. How can I change this without to break the form? views.py class cloud(CreateView): template_name = 'base/cloud.html' form_class = UserForm def get_context_data(self, *