Re: How to pass a set of objects in between two views?

2020-08-24 Thread vipul shinde
from django.shortcuts import render, redirect
from .models import *
from .forms import UserForm
from django.contrib.auth.forms import AuthenticationForm
import random
from django.contrib.auth import login, logout, authenticate

# Create your views here.
def home(request):
return render(request, 'testapp/home.html')

def loginuser(request):
#form = UserForm()
if request.method == 'GET':
form = AuthenticationForm()
return render(request, 'testapp/login.html', {'form':form})
else:
user = authenticate(request, username=request.POST['username'],
password=request.POST['password'])
if user is None:
return render(request, 'testapp/login.html',
{'form':AuthenticationForm(), 'error':'Username or password incorrect'})
else:
login(request, user)
return redirect('paper')

def paper(request):
#objects = Questions.objects.all()
"""count = Questions.objects.all().count()
slice = random.random() * (count-5)
objects = Questions.objects.all()[slice:slice+5]"""
#objects = {{ objects }}
objects = Questions.objects.all().order_by('?')[:5]
return render(request, 'testapp/paper.html', {'objects':objects})

On Mon, Aug 24, 2020 at 7:57 PM hans alexander  wrote:

> Can you share the views.py that you wrote?
> Actually If the page for random set of questions is same for User NOT
> Logged In and User Logged In, the data you called from database will still
> showing up.
>
> On Mon, Aug 24, 2020 at 9:19 PM vipul shinde 
> wrote:
>
>>
>> I'm building a quiz app in which I'm storing questions in the database by
>> creating a model class. I am retrieving a random question set for each user
>> from the database and then rendering them on an HTML page. The problem is
>> after logging a user in, a random set of questions appears but that random
>> set is lost after refreshing the page.
>> How do I solve this
>> One thing that I thought was retrieving the object set in another
>> viewsay after logging a user in and passing it as a dictionary to
>> another view.
>> But I can't find the syntax or any function (if it exists). Please help.
>> I'm using django 3.1 and MySQL as my database
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CANE4xcuDmZCAaB4pzTqvH1d2eGf2b12%2BBPwN90e5_hmK%3DUBeQw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CANE4xcuDmZCAaB4pzTqvH1d2eGf2b12%2BBPwN90e5_hmK%3DUBeQw%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CANV3w%3DYE%3DP6OW4cow0q%3D8uocbUSKoi259CJbRWrJYPo7A51oEw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CANV3w%3DYE%3DP6OW4cow0q%3D8uocbUSKoi259CJbRWrJYPo7A51oEw%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANE4xcv3hx8pkaOh0E5xJg4_mOQjdnkGHt_4%3Dq61yZfMVodFyg%40mail.gmail.com.


How to pass a set of objects in between two views?

2020-08-24 Thread vipul shinde
I'm building a quiz app in which I'm storing questions in the database by
creating a model class. I am retrieving a random question set for each user
from the database and then rendering them on an HTML page. The problem is
after logging a user in, a random set of questions appears but that random
set is lost after refreshing the page.
How do I solve this
One thing that I thought was retrieving the object set in another
viewsay after logging a user in and passing it as a dictionary to
another view.
But I can't find the syntax or any function (if it exists). Please help.
I'm using django 3.1 and MySQL as my database

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANE4xcuDmZCAaB4pzTqvH1d2eGf2b12%2BBPwN90e5_hmK%3DUBeQw%40mail.gmail.com.


Any models field for accepting rating

2020-05-10 Thread vipul shinde
I'm developing an application for a feedback system and I want to accept a
rating from a specific user. It could be anything from like a range from 1
to 10.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANE4xcv-XFskKDu%2Bbw42zHhdaZST18%3DWfzmUht9qgtzky%2Bjb-A%40mail.gmail.com.


can we create two different model classes in one application?

2020-05-10 Thread vipul shinde
I'm trying to create my own custom form instead of the UserCreationForm
that we import in the third website..for which I need two different
models, one for making the user and the other to accept a text from the
user created through the previous model. Is this possible?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANE4xct8ryMmNXatoK9XJ1iARJWsN8aGNbB0ffOwEx8MM5P26Q%40mail.gmail.com.