Was I supposed to be able to create a question on the website using 'runserver'?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Was I supposed to be able to create a question on the website using 'runserver'?

Carlos Henrique
I'm following this Django tutorial. So far I haven't had an issue so far, but now I'm not really sure if I understood it correctly. We created a shortcut function to create questions, but I thought that it was meant to be user-side and when I use 'runserver', on the website there's no such option, only the previously created question. This is the code for the function:
def create_question(question_text, days): """ Create a question with the given `question_text` and published the given number of `days` offset to now (negative for questions published in the past, positive for questions that have yet to be published). """ time = timezone.now() + datetime.timedelta(days=days) return Question.objects.create(question_text=question_text, pub_date=time)

Did I get it wrong? This function is only admin-sided? It's on 'polls/test.py' and it's outside every class.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f4dfe964-3417-4605-af26-d99a0d8fa4b5n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Was I supposed to be able to create a question on the website using 'runserver'?

Jorge Gimeno
That's a helper function to get the Question instances you need for testing.  It's a way to query for those questions without repeating the same code over and over in tests.

-Jorge

On Wed, Nov 11, 2020 at 5:56 AM Carlos Henrique <[hidden email]> wrote:
I'm following this Django tutorial. So far I haven't had an issue so far, but now I'm not really sure if I understood it correctly. We created a shortcut function to create questions, but I thought that it was meant to be user-side and when I use 'runserver', on the website there's no such option, only the previously created question. This is the code for the function:
def create_question(question_text, days): """ Create a question with the given `question_text` and published the given number of `days` offset to now (negative for questions published in the past, positive for questions that have yet to be published). """ time = timezone.now() + datetime.timedelta(days=days) return Question.objects.create(question_text=question_text, pub_date=time)

Did I get it wrong? This function is only admin-sided? It's on 'polls/test.py' and it's outside every class.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f4dfe964-3417-4605-af26-d99a0d8fa4b5n%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANfN%3DK_56zjpn9yO-BvT1ec9KOY%2BOSnnRyJL%2B5E49DHuZ8_fcg%40mail.gmail.com.