django-views

How to prevent Django form being reset after clicking page buttons

二次信任 提交于 2019-12-11 06:20:54
问题 I have a Django form that takes input values from users. The values are then used in making query to a table ResourceBase , which finally returns a list of filtered results. Since the results might be a long list, I added a pagination function with "Prev" and "Next" buttons. My problem is that when I click "Prev" or "Next" button, the form gets restored into default values. And all returned results are all gone. How do I prevent this from happening? I think the form gets reset because of

How to restrict access to objects using detailview class

守給你的承諾、 提交于 2019-12-11 06:08:21
问题 Im trying to limit the display objects to the user who created it. Is it done using a foreign key in the object model? Ex: User 1 may access object 1 User 2 may access object 2 At this moment any user can access any object just entering the correct URL to that object. File views.py from django.shortcuts import render from django.http.response import Http404 from .models import Host from django.views.generic.detail import DetailView from django.views.generic.list import ListView from django

Two views in a Django page

旧城冷巷雨未停 提交于 2019-12-11 05:53:00
问题 I'm having problems displaying the input box of my page. On this same page I would like to have two views, one that accesses and retrieves data and the other a form. As it's an event sign-up page, the first view show the details of a specific event and the second is a view to remove a specific user from the event itself. My views.py def ShowSpecificEvent(request, eventslug): if request.method == 'POST': form = RemovalForm(request.POST) if form.is_valid(): event = Event.objects.get(slug

List of missing records for reverse OneOnOneField in django

余生长醉 提交于 2019-12-11 05:48:27
问题 I have two models with the same primary key: class OperationalDevice(models.Model): ip = models.GenericIPAddressField(primary_key=True) mac = models.CharField() class AllowedDevice(models.Model): ip = models.OneToOneField(OperationalDevice, primary_key=True, on_delete=models.DO_NOTHING, db_constraint=False, db_column='ip') type = models.CharField() owner = models.CharField() I would like to display the list of all AllowedDevices that are down - kind of like: SELECT AllowedDevice.ip from

Django Two Factor Authentication

六眼飞鱼酱① 提交于 2019-12-11 05:38:20
问题 I have recently been reading through the documentation about django-two-factor-authentication which I found here : https://django-two-factor-auth.readthedocs.io/en/stable/installation.html The documentation is great. However, I'm trying to understand the full requirements for this solution. If I implement this package, do I then need to rely on a third party to complete this solution or can two factor authentication be achieved without a third party? My primary concern is the cost associated

Accessing request.META.SERVER_NAME in template

旧巷老猫 提交于 2019-12-11 05:26:49
问题 I call a template like this from my view: return render_to_response('mytemplate.html', context_instance=RequestContext(request)) I'm trying to access the hostname of my current server (in this case, localhost ), but it just prints blank when I place {{request.META.SERVER_NAME}} in the template. In my settings.py file, I don't have any TEMPLATE_CONTEXT_PROCESSORS defined. I'm not sure if I need to specify anything there, or if that could solve the problem. 回答1: You have to add the request

Show Last month progress of user on base of actions on website django

三世轮回 提交于 2019-12-11 05:22:03
问题 I have designed my database like this user = models.ForeignKey(Profile, unique=True, on_delete=models.CASCADE) signup = models.FloatField(default=10) signup_from_user_link = models.FloatField(default=0) post_review = models.FloatField(default=0) total = models.FloatField(default=0) I am calculating overall progress of user by adding all these values . But Now I have to make a change and I want to show progress of last month. Like in last month how much user added in every filed . What will be

objects.all() query not working

时光毁灭记忆、已成空白 提交于 2019-12-11 04:50:47
问题 I am trying to make a form for user creation through django. The user(henceforth developer) can choose from a list of supervisors to get himself registered. Problem is, I am not getting the list of all the supervisors from the query. When I use objects.get(), I receive an error that 2 objects were received. That means that the queries are getting the rows from the database. models.py from django.db import models class UserProfile(models.Model): name = models.CharField(max_length=50,verbose

Django - inlineformset-factory (How to Edit)

痴心易碎 提交于 2019-12-11 04:41:18
问题 I saw many tutorials and questions in many foruns and websites. And when I search for "inline formset-factory" are many links appear. But few talk about how edit, with inline formset-factory. I have a problem in my project, I did it save, but when I will try edit, rise some errors This is my code class Dia_Producao(models.Model): id = models.AutoField(primary_key=True) diaTrabalho = models.CharField("Dia de Trabalho", choices=DIATRABALHO_CHOICES, blank=True, null=False, max_length=10)

Create a restricted area

空扰寡人 提交于 2019-12-11 04:29:06
问题 I'm trying to build a restricted area for a website in which only the registered user can see his personal profile and his posts. The staff users can see all users profile and related posts. This is models.py : ... from django.contrib.auth.models import User class Post(models.Model): authorized_users = models.ManyToManyField( User, related_name="user_set", default=1, ) title = models.CharField(max_length=100) ... As you can see one post can have more then one author( authorized_users ). This