django-views

Async functions in Django views

安稳与你 提交于 2019-12-12 13:33:28
问题 Is it possible to do something like this: def new_query(request,company_uuid,address_uuid,contact_uuid): mcompany = get_object_or_404(Company, uuid=company_uuid) if request.method == 'POST': # If the form has been submitted... form = forms.CompanyQueryForm(request.POST) if form.is_valid(): mquery = form.save(commit = False) mcompany = get_object_or_404(Company, uuid = company_uuid) mquery.company = mcompany mquery.version_number = 1 mquery.parameters = { 'company':company_uuid, 'address'

Reverse URL issue

≡放荡痞女 提交于 2019-12-12 10:57:41
问题 I have a django model defined as from utils.utils import APIModel from django.db import models from django.core.urlresolvers import reverse class DjangoJobPosting(APIModel): title = models.CharField(max_length=50) description = models.TextField() company = models.CharField(max_length=25) def get_absolute_url(self): return reverse('jobs.views.JobDetail', args=[self.pk]) with a view from restless.views import Endpoint from restless.models import serialize from .models import * from utils.utils

Fetch data from form and display in template

旧街凉风 提交于 2019-12-12 10:57:00
问题 I'm trying to modify posts app from a django tutorial- https://github.com/codingforentrepreneurs/Advancing-the-Blog/tree/master/src/posts I'm creating a new field 'userc' in a forms.py: userc = forms.ModelChoiceField(queryset=User.objects.filter(is_staff=True)) I've tried various methods but I'm unable to display the selected user in the template. What should I add in views.py? Edit: I've tried {{ obj.userc }}, {{ instance.userc }} to display the selected user in templates. views.py from

Adding a user/accounts table to Postgres in Django View

我只是一个虾纸丫 提交于 2019-12-12 10:55:03
问题 Go to edit 2 Calling the following adduser function in views.py. I save the user first because it's id (automatically created by Django upon INSERT) is the primary/foreign key for accounts and passwords. Adding a user seems to be working fine, but then when it gets to the Accounts(user=u) , the following error throws: IntegrityError at /adduser insert or update on table "OmniCloud_App_accounts" violates foreign key constraint "user_id_refs_id_468fbcec324e93d2" DETAIL: Key (user_id)=(4) is not

how to return redirect to previous page in Django after POST request

强颜欢笑 提交于 2019-12-12 10:20:54
问题 I'm coding a news website,in the detail news page ,there is a comment fountain,if people want to post comment they need to login first.And I want to make it that,after they login in successfully ,the page can return to previous news page. Here is my views.py: def newsDetailView(request, news_pk): news = News.objects.get(id=news_pk) title = news.title author = news.author_name add_time = news.add_time content = news.content category = news.category tags = news.tag.annotate(news_count=Count(

Django: How to return to previous URL

假装没事ソ 提交于 2019-12-12 09:47:08
问题 Novice here who learned to develop a web app with python using Flask. Now I'm trying to learn django 1.9 by redoing the same app with django. Right now I am stuck at trying to get the current URL and pass it as an argument so that the user can come back once the action on the next page is completed. In Flask, to return to a previous URL, I would use the 'next' parameter and the request.url to get the current url before changing page. In the template you would find something like this: <a href

Django: Generating a queryset from a GET request

安稳与你 提交于 2019-12-12 09:43:35
问题 I have a Django form setup using GET method. Each value corresponds to attributes of a Django model. What would be the most elegant way to generate the query? Currently this is what I do in the view: def search_items(request): if 'search_name' in request.GET: query_attributes = {} query_attributes['color'] = request.GET.get('color', '') if not query_attributes['color']: del query_attributes['color'] query_attributes['shape'] = request.GET.get('shape', '') if not query_attributes['shape']: del

django custom manager with filter parameter

不羁的心 提交于 2019-12-12 09:37:46
问题 I would like to add a custom manager which can be called from a template, but does not affect the entire model (e.g. admin views) and which listens to a parameter set in the request (user_profile). The following is what I have so far: models.py: class CurrentQuerySet(models.query.QuerySet): def current(self): return self.filter(id=1) ## this simplified filter test works.. class CurrentManager(models.Manager): use_for_related_fields = True def get_query_set(self): return CurrentQuerySet(self

One url for two different views

守給你的承諾、 提交于 2019-12-12 09:25:56
问题 I'm developing a site that have two types of User, and the project's owners want two different home (templates) after the user is authenticated, so, I tried this: url # home a url(r'^home/$', HomeAView.as_view(), name='home-a'), # home b url(r'^home/$', HomeBView.as_view(), name='home-b'), And some like that at into my log_in view: if user.typeUser == "HA": print('Go to Home A') return redirect(reverse('sesion:home-a')) else: print('Go to Home B') return redirect(reverse('sesion:home-b')) So

Django login from in modal window

社会主义新天地 提交于 2019-12-12 08:13:12
问题 I have a login form and I want to put in modal window in header. Urls.py url(r'^account/login/$', appuser_views.LoginView.as_view(template_name = 'account/login/index.html', form_class = appuser_forms.LoginForm, target_url = LOGIN_TARGET_URL)), views.py class LoginView(ResendEmailToUsersMixin, AjaxFormView): def process_form(self, request, form): data = form.cleaned_data a = AppUserCredential.objects.select_related('appuser').filter( data1 = data['email_address'], credential_type =