django-views

Django pre-filling data in form from URL

依然范特西╮ 提交于 2019-12-11 09:58:51
问题 So i have a button on my detailView page for my model 'patient', and that takes you to a createView for my other model 'appointment'. What i want is the foreign key field of the appointment to be pre-filled depending on what detailView i come from. Here is my code so far: urls.py: # /patients/appointment/add url(r'appointment/add/$', views.appointmentCreate.as_view(), name='appointment-create'), models.py: class patient(models.Model): TITLE_CHOICES = ( ('Mr', 'Mr'), ('Mrs', 'Mrs'), ('Ms', 'Ms

Django templating language syntax for navbar notifications

五迷三道 提交于 2019-12-11 09:55:19
问题 I am trying to use the Django templating language in my Django Channels 2.1.2 project to render out any unread chat messages in a Facebook-style notification popup. The list of unread chatmessages (in their respective threads ) are not displaying because I am having trouble with the correct syntax. This is how the front end looks. When you click the message icon, the notification disappears. I have a Notification model class Notification(models.Model): notification_user = models.ForeignKey

Django HttpResponse - response with file and content

风流意气都作罢 提交于 2019-12-11 09:49:08
问题 Is there an easy way to do the following? after getting the request in the view, send back to the user a file, plus a re-rendered template of the page? something like "merging" reponse with a file and render_to_response This is how I return a response with a file: filename = "/path/to/somewhere" wrapper = FileWrapper(open(filename)) content_type = mimetypes.guess_type(filename)[0] response = HttpResponse(wrapper,content_type=content_type) response['Content-Length'] = os.path.getsize(filename)

Wildcard searching in Django

蓝咒 提交于 2019-12-11 08:57:09
问题 How can we do a wildcard searching in Django. If i am filtering username from a list in database, how is it possible to display the filtered data with those exact usernames or part of it.? def filter(request): val3='' if request.GET.has_key('choices'): val2=request.GET.get('choices') if request.GET.has_key('textField'): val3=request.GET.get('textField') if request.POST: val2=request.POST.get('choices') val3=request.POST.get('textField') if val2=='Designation': newData = EmployeeDetails

How to insert default value in database table when user account is created in Django?

不羁的心 提交于 2019-12-11 08:41:40
问题 I am using postgre database have 10 channel in my database. This is my models with channelId and userId as foreign key: class Count(models.Model): userId = models.ForeignKey(User, on_delete=models.CASCADE) channelId = models.ForeignKey(News_Channel, on_delete=models.CASCADE) rate = models.PositiveIntegerField(default=0) def __str__(self): return self.channelId.name class Meta: ordering = ["-id"] I want when a user account is created then 3 row inserted in the table for all 3 channelId and

How To Prevent Double Submit With Form Validation

半世苍凉 提交于 2019-12-11 07:52:53
问题 I have been researching this problem for the last day or so. I am trying to prevent the user from double clicking on the submit button for my django project and submitting the form twice. I am also doing form validation so if the form validation fails, I don't want to disable the submit button. My form validation is preventing a double submit in this case because I have a unique field in my form which is preventing the double submit. I am also doing a redirect after the submit, but if I

Django: How to save the POST.get of a checkbox as false (0) in a DataBase?

送分小仙女□ 提交于 2019-12-11 07:34:54
问题 I'm trying to save the value of a checkbox as true or false in a database. I have to use a model for this. If the box is checked the value of '1' is saved. However, if the box is not checked I get the error message: Django Version: 1.9.4 Exception Type: IntegrityError Exception Value: (1048, "Column 'completed' cannot be null") Currently my setup looks like this: In models.py I have: class myClass(models.Model): completed = models.BooleanField(default=False, blank=True) In views.py I have:

Show project only if owner or member

老子叫甜甜 提交于 2019-12-11 07:27:01
问题 In the project management app I'm working on I want it only to be possible to show a project if the user is admin of the project or a member of the project. The view below doesn't (of course) work, but it shows one way of checking if the user is admin of the project. One way I know of how to check whether a user is a member or not is by using the following query: projects = get_list_or_404(Project.objects.filter(users__id__iexact=request.user.id)) ...though I have no idea of how to use these

Using HttpResponseRedirect() in a Django view where context has to be passed

不羁岁月 提交于 2019-12-11 06:36:24
问题 In this Django app of mine, I use a ListView class to list user-uploaded photos. One can upvote or downvote these photos. Non-authenticated users can see the photos, but not allowed to cast votes. An unignorable section of my users use legacy devices that can't support JS. For such users, upvote or downvote isn't AJAX-enabled. Instead, the entire page refreshes. I ensure the page refresh still lands such users on the same photo they voted. I do this via the <a name="section{{ forloop_counter

django image storage cdn

心不动则不痛 提交于 2019-12-11 06:34:45
问题 I have been using rackspace CDN for the last few months with django-imagekit and django-cumulus. And I am not really happy with the results. I seem to get load of errors because of timeouts etc. File "/www/django_test1/omu2/src/python-cloudfiles/cloudfiles/connection.py", line 347, in get_container return Container(self, container_name, count, size) File "/www/django_test1/omu2/src/python-cloudfiles/cloudfiles/container.py", line 83, in __init__ self._fetch_cdn_data() File "/www/django_test1