Re: Models as choices

2020-04-16 Thread Antje Kazimiers
with a Foreign Key field, one-to-many relationship:

https://docs.djangoproject.com/en/3.0/topics/db/examples/many_to_one/

Antje

On 4/16/20 6:52 AM, shreehari Vaasistha L wrote:
> how can i use model x values as choices for model y ?
>
> for eg:
> |
> classcountries(models.Model):
>  country =models.CharField(max_length=200)
>
>  def__str__(self):
>  returnself.country
>
> classUser(AbstractUser):
>  """User model."""
>
>  username =None
>  full_name =models.CharField(_("Full
> Name"),max_length=50,default="Full Name")
>  country_choices =models.CharField(choices=countries
> |
> -- 
> 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/683251c6-27ab-4454-90d6-532fdcc749ce%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f6aeed6e-de34-f8f6-ce26-31151d4dee83%40gmail.com.


Re: Models as choices

2020-04-16 Thread shreehari Vaasistha L


Object of type ValueError is not JSON serializable


getting this above error

On Thursday, April 16, 2020 at 12:57:16 PM UTC+5:30, Antje Kazimiers wrote:
>
> with a Foreign Key field, one-to-many relationship:
>
> https://docs.djangoproject.com/en/3.0/topics/db/examples/many_to_one/
>
> Antje
> On 4/16/20 6:52 AM, shreehari Vaasistha L wrote:
>
> how can i use model x values as choices for model y ?
>
> for eg: 
> class countries(models.Model):
>  country = models.CharField(max_length=200)
>
>  def __str__(self):
>  return self.country 
>
> class User(AbstractUser):
>  """User model."""
>
>  username = None
>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
> Name") 
>  country_choices = models.CharField(choices=countries
> -- 
> 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...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/683251c6-27ab-4454-90d6-532fdcc749ce%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12580555-d71d-435c-abbb-449a260fdfe7%40googlegroups.com.


Re: Models as choices

2020-04-16 Thread shreehari Vaasistha L


Object of type ValueError is not JSON serializable

getting this above error.

here's my views.py
class UserCreateApiView(CreateAPIView):
   serializer_class = UserCreateSerializer
   def post(self,request):
   try:
   serializer=UserCreateSerializer(data=request.data)
   if serializer.is_valid():
   new_user = User()

new_user.highest_degree=serializer.data['highest_degree']
   
#new_user.state_registered=serializer.data['state_registered']
   new_user.country_choices=serializer.data['country_choices']

new_user.save()
   print(new_user.doc_id)
   return Response(status=status.HTTP_200_OK)
   return Response(status=status.HTTP_406_NOT_ACCEPTABLE)
   except Exception as e:
   return Response(e)
have mentioned all fields in serializers.py



On Thursday, April 16, 2020 at 12:57:16 PM UTC+5:30, Antje Kazimiers wrote:
>
> with a Foreign Key field, one-to-many relationship:
>
> https://docs.djangoproject.com/en/3.0/topics/db/examples/many_to_one/
>
> Antje
> On 4/16/20 6:52 AM, shreehari Vaasistha L wrote:
>
> how can i use model x values as choices for model y ?
>
> for eg: 
> class countries(models.Model):
>  country = models.CharField(max_length=200)
>
>  def __str__(self):
>  return self.country 
>
> class User(AbstractUser):
>  """User model."""
>
>  username = None
>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
> Name") 
>  country_choices = models.CharField(choices=countries
> -- 
> 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...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/683251c6-27ab-4454-90d6-532fdcc749ce%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87fad0b6-96d2-43fc-87cf-ffdddc855c5f%40googlegroups.com.


Re: Models as choices

2020-04-16 Thread Kasper Laudrup

Hi Shreehari

On 16/04/2020 10.17, shreehari Vaasistha L wrote:

Object of type ValueError is not JSON serializable


getting this above error



First of all, don't highjack other unrelated threads. Create your own 
with a descriptive subject.


You get the error because of the lines:

except Exception as e:
   return Response(e)

You cannot serialize the exception object, but your real problem is most 
likely the actual exception being thrown.


Try to remove the entire try/except block. You most likely don't want to 
return errors in your code to the user anyway so returning an HTTP 500 
to the user and letting Django write the exception message and 
stacktrace in your log is probably much better.


Kind regards,

Kasper Laudrup

--
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/c6c85506-e72b-fd3f-b79a-67412641007b%40stacktrace.dk.


Re: Models as choices

2020-04-16 Thread shreehari Vaasistha L
Thanks for helping me out .

On Thursday, April 16, 2020 at 2:34:13 PM UTC+5:30, Kasper Laudrup wrote:
>
> Hi Shreehari 
>
> On 16/04/2020 10.17, shreehari Vaasistha L wrote: 
> > Object of type ValueError is not JSON serializable 
> > 
> > 
> > getting this above error 
> > 
>
> First of all, don't highjack other unrelated threads. Create your own 
> with a descriptive subject. 
>
> You get the error because of the lines: 
>
> except Exception as e: 
> return Response(e) 
>
> You cannot serialize the exception object, but your real problem is most 
> likely the actual exception being thrown. 
>
> Try to remove the entire try/except block. You most likely don't want to 
> return errors in your code to the user anyway so returning an HTTP 500 
> to the user and letting Django write the exception message and 
> stacktrace in your log is probably much better. 
>
> Kind regards, 
>
> Kasper Laudrup 
>

-- 
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/87eade6b-38e0-4b61-9d3f-0d6f08b2ed85%40googlegroups.com.


Re: user visit count

2020-04-16 Thread Motaz Hejaze
Great

On Thu, 16 Apr 2020, 6:53 am shreehari Vaasistha L, 
wrote:

> Done
>
> On Wednesday, April 15, 2020 at 6:55:37 PM UTC+5:30, Motaz Hejaze wrote:
>>
>> no standard for this , but thinking out loud with you ..
>>
>> you can make a many to many model ( table ) of 3 columns , first column
>> will be user id , second column will be object id , third column will be
>> number of visits ( integer  initial value 0 ) ,  every time the object view
>> is called you'll query the table for object.id if not found ( for first
>> time , create a new row with this object.id and request.user.id and put
>> number_of_visits column  = 1 ) , if found then filter by user.id , if
>> found increase number in number_of_visits column by one , if filter not
>> returning thing then create a new row with object.id and user.id and put
>> number_of_visits column  = 1
>>
>> On Wed, Apr 15, 2020 at 2:29 PM shreehari Vaasistha L <
>> shreeh...@gmail.com> wrote:
>>
>>> Thank you!
>>> But can there be any simple implementation as i just want to count
>>> number of times a user has viewed a post
>>>
>>> On Wednesday, April 15, 2020 at 5:48:36 PM UTC+5:30, Tim Wilson wrote:

 I'm planning to use django-hitcount too, but please be aware that it's
 not yet compatible with Django 3.x. There's a patch that needs to be
 applied and a release forthcoming that should take care of it.

 -Tim

 On Wed, Apr 15, 2020, at 4:38 AM, Omkar Parab wrote:

 Django hit count package will help you..

 On Wed, Apr 15, 2020, 1:09 PM shreehari Vaasistha L <
 shreeh...@gmail.com> wrote:

 how can i get the number of views of an endpoint by a single user.


 --
 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...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/b9e434ba-8378-45cb-a67f-b344773340b6%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 django...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CAJY8mfxe%3Dgx4YnJj_%2BWLuVD-iTaeNy0BhMR4U1_bAXa93ObAMg%40mail.gmail.com
 
 .


 --
 Tim Wilson
 President, Savvy Technology Group
 phone: 612-599-5470

 --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/36fd6a9b-e959-49ee-9183-f18c26daf1c9%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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9c1ca4ac-5b9d-4a87-811f-185f539c6de7%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHV4E-fsBxq-OM2j1x8or9eyjKhw85aXhY_SFu9Y4E9BUY1-nQ%40mail.gmail.com.


Re: Cannot Redirect to other page

2020-04-16 Thread Gavin Wiener
So the "return" inside the inner function won't automatically "trigger". 
`redirect` is a shortcut function which constructs a HttpResponseRedirect. 
At the moment, you're calling the function, and the HttpResponseRedirect 
instance is returned from the function you're not actually doing anything 
with it, you're throwing it away. You'd need to either `return verifyGame2` 
or save the response `redirect_instance = verifyGame2` and then `return 
redirect_instance` 

But your flow in this function seems very odd. Your actions are exactly the 
same regardless if it's a GET or POST. Your form's submit should be POST 
and not a GET (since you're sending data). In that case; your code should 
be looking at the request's method, if it's a GET, then render the 
game2.html, if it's a POST, then you need fetch the POST data (the answer) 
and do the processing as you've done.

It's quite unnecessary to have an inner function in this situation.

Quite a lot to improve on with this FBV.

On Wednesday, April 15, 2020 at 8:22:35 PM UTC+8, pui hei Li wrote:
>
> I am writing a view that retrieve an answer from game2.html, then check 
> the answer; if the answer is correct, the view will redirect user to 
> correct.html, if the answer is incorrect, then user will be redirected to 
> incorrect.html. 
>
> The problem now is after clicking the submit button, user won't be 
> redirected. And after clicking the submit button, the url changed from 
> localhost:8000/game2 to 
> http://localhost:8000/game2/?ans2=4&game2Answer=Submit 
>
> It seems the view is not verifying the answer, and it is also redirecting 
> user to anywhere.
>
> How do I solve it?
>
> *morse_logs/views.py*
>
> @login_required()
> def game2(request):
> """The Game2 page"""
> if request.user and not request.user.is_anonymous:
> user = request.user
>
> def verifyGame2(val1):
> user_score, created = userScore.objects.get_or_create(user=user)
>
> if val1 == 4:
> # user's score declared in model increase 5points
> # display correct and 5 points added to user
> user_score.score += 5
> user_score.save()
> return redirect(reverse('morse_logs:incorrect'))
> else:
> # user's score declared in model has no point
> # display incorrect and 0 point added to user
> return redirect(reverse('morse_logs:incorrect'))
>
>
> ans2 = request.GET.get('ans2', '')
> if ans2 == '':
> ans2 = 0
>
> verifyGame2(int(ans2))
>
> return render(request, 'morse_logs/game2.html')
>
>
> *morse_logs/game2.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> GAME 2
> 
> GAME 2
> 2 + 2 = ?
> 
> 
> 
> 
> 
> {% endblock content %}
>
>
> *morse_logs/correct.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Correct!
> 
> Congratulations! Your answer is CORRECT!
> 
> {% endblock content %}
>
>
> *morse_logs/incorrect.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Inorrect...
> 
> Unfortunately! Your answer is Incorrect!
> 
> {% endblock content %}
>
>
> *morse_logs/urls.py*
>
> from django.urls import path, include
> from morse_logs import views
>
> app_name = 'morse_logs'
>
> urlpatterns = [
> #The path() function is passed four arguments, two required: route and 
> view, and two optional: kwargs, and name.
> # Home Page
> path(r'', views.index, name='index'),
> # Page that shows all topics
> path(r'topics/', views.topics, name='topics'),
> path(r'cipher/', views.cipher, name='cipher'),
> path(r'decipher/', views.decipher, name='decipher'),
> path(r'tutorialIndex/', views.tutorialIndex, name='tutorialIndex'),
> path(r'gameDirectory/', views.gameDirectory, name='gameDirectory'),
> path(r'correct/', views.correct, name='correct'),
> path(r'incorrect/', views.incorrect, name='incorrect'),
> path(r'game1/', views.game1, name='game1'),
> path(r'game2/', views.game2, name='game2'),
>
> ]
>
>

-- 
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/0e1cf17c-a5cf-4e58-b3de-9e243ee8ed3b%40googlegroups.com.


Re: AddTocard And cart Not Working Plese Help Me

2020-04-16 Thread Mohamed Johnson
Hello,
Please take a look at the value stored on tour localStorage

On Thu, Apr 16, 2020 at 08:06 kkwaqar786  wrote:

> Error JavaScript Please Solve My Problems
>
> [image: er.JPG]
>
> [image: erc.JPG]
>
>
> Admin:
> username:waqar
> password:1234
>
> --
> 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/3ce81c59-587c-46d6-9cae-65e4fd2b5fb1%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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANXf73z_SYW4S-UKEB8cx50aANDPCVXQ-DYT6H6hwOL0j_w7uQ%40mail.gmail.com.


Re: Models as choices

2020-04-16 Thread Gavin Wiener
Couldn't the User just have a ForeignKey on countries?

On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L 
wrote:
>
> how can i use model x values as choices for model y ?
>
> for eg:
> class countries(models.Model):
>  country = models.CharField(max_length=200)
>
>  def __str__(self):
>  return self.country 
>
> class User(AbstractUser):
>  """User model."""
>
>  username = None
>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
> Name") 
>  country_choices = models.CharField(choices=countries
>

-- 
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/b1d051a8-ee61-4b0a-b5e4-66d0315306fa%40googlegroups.com.


Re: Capture URL values in a CBV

2020-04-16 Thread Gavin Wiener
Hey Tim

The bigger question is, what are you trying to achieve? 

With the DetailView, fetching the object with the primary key is already 
handled for you, as you've seen the object will already be available in the 
template.

This website is very useful to know which functions are implemented in a 
class-based view, and which variables are available.

http://ccbv.co.uk/


On Thursday, April 16, 2020 at 8:26:00 AM UTC+8, tim042849 wrote:
>
> using django.VERSION (2, 1, 5, 'final', 0) with 
>
> python 3.7.2 on ubuntu 16.04 
>
> Given the URL pattern below:
>
> path('', ArticleDetailView.as_view(), name='article_detail'),
>
> And the view as below:
>
> class ArticleDetailView(DetailView):
> model = Article
> template_name = 'article_detail.html'
> login_url = 'login'
>
> I can access the variable pk from a template as 
>
> article.pk
>
> But I don't know how to access the pk variable from the view itself.
>
> Adding the get_queryset method to the view doesn't work
>
> example 
>
> def get_queryset(self):
> print(self.kwargs["pk"])
>
> results in 
>
> 'NoneType' object has no attribute 'filter'
>
> Trying 
> def get_object(self):
> queryset = self.filter_queryset(self.get_queryset())
> obj = queryset.get(pk=self.kwargs['pk'])
> return obj
> results in
>   'ArticleDetailView' object has no attribute 'filter_queryset'
>
> Please advise - pretty basic for django, new to me :)
> thanks
>
> -- 
> Timtj49.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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/39595843-0a01-4ffb-95b9-46d2d3c442e3%40googlegroups.com.


How to generate breadcrums

2020-04-16 Thread 'MH' via Django users
Hi there

I need some advice how to implement breadcrumbs in a base.html.

I have already installed django-bootstrap-breadcrumbs, registered it in the 
apps and so on. So far I would say, it's working,

Just for testing purposes it looks like this:
 
 {% load django_bootstrap_breadcrumbs %}
 {% block breadcrumbs %}
 {% clear_breadcrumbs %}
 {% breadcrumb "Home" "/" %}
 {% breadcrumb "Users and groups" "dummy" %}
 {% breadcrumb "tbd" "mockupview.index" %}
 {% endblock %}
 {% render_breadcrumbs %}
 


However, I would like to generate the breadcrumbs based on which view is 
extending the base.html file. And I do not know how to achieve that.

Do you have any advice for me?

-- 
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/2b3823c6-f8bc-4ff0-8ed1-0943e9ced832%40googlegroups.com.


Re: How to generate breadcrums

2020-04-16 Thread 'MH' via Django users
PS: I was just asking myself if I could somehow tell django what the 
hierarchy of views might be instead of defining the breadcrumbs for each 
view manually.

-- 
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/a0e67163-1228-4254-af7d-7d1d878461aa%40googlegroups.com.


Re: Cannot Redirect to other page

2020-04-16 Thread pui hei Li
Thank you for your reply, but I don't really understand how am i able to
make it to the page I want, does it mean I need to write a new function in
view and pass in the retrieved answer from user, then do the redirection/
rendering? Could you give me some hints about how the syntax would be,
because I am a total newbie in Django and couldn't find much resources
about my situation. Thank you!

Gavin Wiener  於 2020年4月16日週四 下午8:00寫道:

> So the "return" inside the inner function won't automatically "trigger".
> `redirect` is a shortcut function which constructs a HttpResponseRedirect.
> At the moment, you're calling the function, and the HttpResponseRedirect
> instance is returned from the function you're not actually doing anything
> with it, you're throwing it away. You'd need to either `return verifyGame2`
> or save the response `redirect_instance = verifyGame2` and then `return
> redirect_instance`
>
> But your flow in this function seems very odd. Your actions are exactly
> the same regardless if it's a GET or POST. Your form's submit should be
> POST and not a GET (since you're sending data). In that case; your code
> should be looking at the request's method, if it's a GET, then render the
> game2.html, if it's a POST, then you need fetch the POST data (the answer)
> and do the processing as you've done.
>
> It's quite unnecessary to have an inner function in this situation.
>
> Quite a lot to improve on with this FBV.
>
> On Wednesday, April 15, 2020 at 8:22:35 PM UTC+8, pui hei Li wrote:
>>
>> I am writing a view that retrieve an answer from game2.html, then check
>> the answer; if the answer is correct, the view will redirect user to
>> correct.html, if the answer is incorrect, then user will be redirected to
>> incorrect.html.
>>
>> The problem now is after clicking the submit button, user won't be
>> redirected. And after clicking the submit button, the url changed from
>> localhost:8000/game2 to
>> http://localhost:8000/game2/?ans2=4&game2Answer=Submit
>>
>> It seems the view is not verifying the answer, and it is also redirecting
>> user to anywhere.
>>
>> How do I solve it?
>>
>> *morse_logs/views.py*
>>
>> @login_required()
>> def game2(request):
>> """The Game2 page"""
>> if request.user and not request.user.is_anonymous:
>> user = request.user
>>
>> def verifyGame2(val1):
>> user_score, created = userScore.objects.get_or_create(user=user)
>>
>> if val1 == 4:
>> # user's score declared in model increase 5points
>> # display correct and 5 points added to user
>> user_score.score += 5
>> user_score.save()
>> return redirect(reverse('morse_logs:incorrect'))
>> else:
>> # user's score declared in model has no point
>> # display incorrect and 0 point added to user
>> return redirect(reverse('morse_logs:incorrect'))
>>
>>
>> ans2 = request.GET.get('ans2', '')
>> if ans2 == '':
>> ans2 = 0
>>
>> verifyGame2(int(ans2))
>>
>> return render(request, 'morse_logs/game2.html')
>>
>>
>> *morse_logs/game2.html*
>>
>> {% extends "morse_logs/base.html" %}
>>
>> {% block content %}
>> GAME 2
>> 
>> GAME 2
>> 2 + 2 = ?
>> 
>> 
>> 
>> 
>> 
>> {% endblock content %}
>>
>>
>> *morse_logs/correct.html*
>>
>> {% extends "morse_logs/base.html" %}
>>
>> {% block content %}
>> Correct!
>> 
>> Congratulations! Your answer is CORRECT!
>> 
>> {% endblock content %}
>>
>>
>> *morse_logs/incorrect.html*
>>
>> {% extends "morse_logs/base.html" %}
>>
>> {% block content %}
>> Inorrect...
>> 
>> Unfortunately! Your answer is Incorrect!
>> 
>> {% endblock content %}
>>
>>
>> *morse_logs/urls.py*
>>
>> from django.urls import path, include
>> from morse_logs import views
>>
>> app_name = 'morse_logs'
>>
>> urlpatterns = [
>> #The path() function is passed four arguments, two required: route and 
>> view, and two optional: kwargs, and name.
>> # Home Page
>> path(r'', views.index, name='index'),
>> # Page that shows all topics
>> path(r'topics/', views.topics, name='topics'),
>> path(r'cipher/', views.cipher, name='cipher'),
>> path(r'decipher/', views.decipher, name='decipher'),
>> path(r'tutorialIndex/', views.tutorialIndex, name='tutorialIndex'),
>> path(r'gameDirectory/', views.gameDirectory, name='gameDirectory'),
>> path(r'correct/', views.correct, name='correct'),
>> path(r'incorrect/', views.incorrect, name='incorrect'),
>> path(r'game1/', views.game1, name='game1'),
>> path(r'game2/', views.game2, name='game2'),
>>
>> ]
>>
>> --
> 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/0e1cf17c-a5cf-

Re: d

2020-04-16 Thread Muhammad Abdullah Nabeel
thank you, i got this

On Mon, Feb 24, 2020 at 6:56 PM Kasper Laudrup 
wrote:

> Hi Muhammed,
>
> On 24/02/2020 13.22, Muhammad Abdullah Nabeel wrote:
> > I want to share file as a software that can be installed. not
> > necessarily it should be a website . like it can be given to another
> > person in a USB Drive and other person opens a file that shows "install
> > it" and clicking on that button the other computer gets installed that
> > software and the other computer has not downloaded  Django or python
> > from the internet
> >
>
> You are most likely looking for something like pyinstaller:
>
> https://www.pyinstaller.org/
>
> This is not related to Django at all.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> 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/8ca448d9-186a-fec7-c621-040e5faaa29a%40stacktrace.dk
> .
>

-- 
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/CAA-Why3A%3D3T7mTpkZO3uQ7xV0kkL%3DyOi2a9KX55md3pX5tM3pQ%40mail.gmail.com.


Re: d

2020-04-16 Thread Muhammad Abdullah Nabeel
thank you, i got this


On Mon, Feb 24, 2020 at 7:25 PM Motaz Hejaze  wrote:

> Ok i got it Mohammed ,
>
> Kindly checkout PyInstaller 
>
> Django is a web framework used to create websites and web services
>
>
> On Mon, Feb 24, 2020 at 3:56 PM Kasper Laudrup 
> wrote:
>
>> Hi Muhammed,
>>
>> On 24/02/2020 13.22, Muhammad Abdullah Nabeel wrote:
>> > I want to share file as a software that can be installed. not
>> > necessarily it should be a website . like it can be given to another
>> > person in a USB Drive and other person opens a file that shows "install
>> > it" and clicking on that button the other computer gets installed that
>> > software and the other computer has not downloaded  Django or python
>> > from the internet
>> >
>>
>> You are most likely looking for something like pyinstaller:
>>
>> https://www.pyinstaller.org/
>>
>> This is not related to Django at all.
>>
>> Kind regards,
>>
>> Kasper Laudrup
>>
>> --
>> 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/8ca448d9-186a-fec7-c621-040e5faaa29a%40stacktrace.dk
>> .
>>
> --
> 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/CAHV4E-c9g_J7dFofsa6W7kTKCA7KT49-wCRPqpRPbB_1woxzxw%40mail.gmail.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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA-Why3wQ2LEc%3DDhWZjwhi7nBr0ufVm7GT0THJsA%3D2V8KP0GdQ%40mail.gmail.com.


Re: Cannot Redirect to other page

2020-04-16 Thread Gavin Wiener
I did include some examples, the last sentence of the first paragraph.

You need to get rid of the inner function, I don't know why it was created. 
It needs to look more like this

if request.method == "GET":



On Wednesday, April 15, 2020 at 8:22:35 PM UTC+8, pui hei Li wrote:
>
> I am writing a view that retrieve an answer from game2.html, then check 
> the answer; if the answer is correct, the view will redirect user to 
> correct.html, if the answer is incorrect, then user will be redirected to 
> incorrect.html. 
>
> The problem now is after clicking the submit button, user won't be 
> redirected. And after clicking the submit button, the url changed from 
> localhost:8000/game2 to 
> http://localhost:8000/game2/?ans2=4&game2Answer=Submit 
>
> It seems the view is not verifying the answer, and it is also redirecting 
> user to anywhere.
>
> How do I solve it?
>
> *morse_logs/views.py*
>
> @login_required()
> def game2(request):
> """The Game2 page"""
> if request.user and not request.user.is_anonymous:
> user = request.user
>
> def verifyGame2(val1):
> user_score, created = userScore.objects.get_or_create(user=user)
>
> if val1 == 4:
> # user's score declared in model increase 5points
> # display correct and 5 points added to user
> user_score.score += 5
> user_score.save()
> return redirect(reverse('morse_logs:incorrect'))
> else:
> # user's score declared in model has no point
> # display incorrect and 0 point added to user
> return redirect(reverse('morse_logs:incorrect'))
>
>
> ans2 = request.GET.get('ans2', '')
> if ans2 == '':
> ans2 = 0
>
> verifyGame2(int(ans2))
>
> return render(request, 'morse_logs/game2.html')
>
>
> *morse_logs/game2.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> GAME 2
> 
> GAME 2
> 2 + 2 = ?
> 
> 
> 
> 
> 
> {% endblock content %}
>
>
> *morse_logs/correct.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Correct!
> 
> Congratulations! Your answer is CORRECT!
> 
> {% endblock content %}
>
>
> *morse_logs/incorrect.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Inorrect...
> 
> Unfortunately! Your answer is Incorrect!
> 
> {% endblock content %}
>
>
> *morse_logs/urls.py*
>
> from django.urls import path, include
> from morse_logs import views
>
> app_name = 'morse_logs'
>
> urlpatterns = [
> #The path() function is passed four arguments, two required: route and 
> view, and two optional: kwargs, and name.
> # Home Page
> path(r'', views.index, name='index'),
> # Page that shows all topics
> path(r'topics/', views.topics, name='topics'),
> path(r'cipher/', views.cipher, name='cipher'),
> path(r'decipher/', views.decipher, name='decipher'),
> path(r'tutorialIndex/', views.tutorialIndex, name='tutorialIndex'),
> path(r'gameDirectory/', views.gameDirectory, name='gameDirectory'),
> path(r'correct/', views.correct, name='correct'),
> path(r'incorrect/', views.incorrect, name='incorrect'),
> path(r'game1/', views.game1, name='game1'),
> path(r'game2/', views.game2, name='game2'),
>
> ]
>
>

-- 
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/43b5d873-fada-40ec-bd0e-fc3cfa5b6bf7%40googlegroups.com.


Re: Cannot Redirect to other page

2020-04-16 Thread Gavin Wiener
I did include example, the last sentence of the first paragraph.

You need to get rid of the inner function, I don't know why that was 
written. I needs to look more

if request.method =="GET":
   return the regular page
elif request.method == "POST":
   process the answers that have been sent by the user

Basically follow this, 
https://docs.djangoproject.com/en/3.0/topics/forms/#get-and-post

You'll need to make changes to;

1. Your template
2. Removing the inner function
3. Processing the form correctly
4. Handling the GET and POST differently


On Wednesday, April 15, 2020 at 8:22:35 PM UTC+8, pui hei Li wrote:
>
> I am writing a view that retrieve an answer from game2.html, then check 
> the answer; if the answer is correct, the view will redirect user to 
> correct.html, if the answer is incorrect, then user will be redirected to 
> incorrect.html. 
>
> The problem now is after clicking the submit button, user won't be 
> redirected. And after clicking the submit button, the url changed from 
> localhost:8000/game2 to 
> http://localhost:8000/game2/?ans2=4&game2Answer=Submit 
>
> It seems the view is not verifying the answer, and it is also redirecting 
> user to anywhere.
>
> How do I solve it?
>
> *morse_logs/views.py*
>
> @login_required()
> def game2(request):
> """The Game2 page"""
> if request.user and not request.user.is_anonymous:
> user = request.user
>
> def verifyGame2(val1):
> user_score, created = userScore.objects.get_or_create(user=user)
>
> if val1 == 4:
> # user's score declared in model increase 5points
> # display correct and 5 points added to user
> user_score.score += 5
> user_score.save()
> return redirect(reverse('morse_logs:incorrect'))
> else:
> # user's score declared in model has no point
> # display incorrect and 0 point added to user
> return redirect(reverse('morse_logs:incorrect'))
>
>
> ans2 = request.GET.get('ans2', '')
> if ans2 == '':
> ans2 = 0
>
> verifyGame2(int(ans2))
>
> return render(request, 'morse_logs/game2.html')
>
>
> *morse_logs/game2.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> GAME 2
> 
> GAME 2
> 2 + 2 = ?
> 
> 
> 
> 
> 
> {% endblock content %}
>
>
> *morse_logs/correct.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Correct!
> 
> Congratulations! Your answer is CORRECT!
> 
> {% endblock content %}
>
>
> *morse_logs/incorrect.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Inorrect...
> 
> Unfortunately! Your answer is Incorrect!
> 
> {% endblock content %}
>
>
> *morse_logs/urls.py*
>
> from django.urls import path, include
> from morse_logs import views
>
> app_name = 'morse_logs'
>
> urlpatterns = [
> #The path() function is passed four arguments, two required: route and 
> view, and two optional: kwargs, and name.
> # Home Page
> path(r'', views.index, name='index'),
> # Page that shows all topics
> path(r'topics/', views.topics, name='topics'),
> path(r'cipher/', views.cipher, name='cipher'),
> path(r'decipher/', views.decipher, name='decipher'),
> path(r'tutorialIndex/', views.tutorialIndex, name='tutorialIndex'),
> path(r'gameDirectory/', views.gameDirectory, name='gameDirectory'),
> path(r'correct/', views.correct, name='correct'),
> path(r'incorrect/', views.incorrect, name='incorrect'),
> path(r'game1/', views.game1, name='game1'),
> path(r'game2/', views.game2, name='game2'),
>
> ]
>
>

-- 
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/f4db16e3-e914-4eea-af8d-4ff04ec1abd8%40googlegroups.com.


Re: Callable field in fieldset's field

2020-04-16 Thread 'Federico Capoano' via Django users
Is this the kind of thing you're looking for?
https://github.com/openwisp/openwisp-firmware-upgrader/tree/1e9fa26d75a48ae9274c2708ea9a10134a2bb9d0/openwisp_firmware_upgrader/base/admin.py#L150-L186

Fed


On Wednesday, April 15, 2020 at 4:15:48 PM UTC-5, Gagan Deep wrote:
>
> Greetings of the day, 
>
> I have defined a model admin inheriting from admin.ModelAdmin class. There 
> is one of the fields which I want to show on the admin dashboard which is a 
> function. I read in Django docs that for a callable function to be a field, 
> it should be added in readonly_fields. So far, it was working great. The 
> problem arose when I mentioned that callable field in the fieldset. 
>
> This worked fine:
> class Myadmin(admin.ModelAdmin):
> readonly_fields = ('my_callable_field', )
> fields = ('my_callable_field' )
>
>
> But, doing this popped Unknown field(s) (my_callable_field) specified for 
> . Check fields/fieldsets/exclude attributes of class Myadmin
> class Myadmin(admin.ModelAdmin):
> readonly_fields = ('my_callable_field', )
> fieldsets = (
> (None, {'fields': ('my_callable_field',)}),
> )
>
> I don't understand why this is happening.
>

-- 
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/dd24c6eb-fcaa-41dc-ac78-6f2ba700c5e9%40googlegroups.com.


problem with admin panel

2020-04-16 Thread Cristhian Heredia Claure

Hello everyone Sorry if it's not correct to post here this issue that I 
have... In a LINUX environment, after all configuration for my project, 
when I try to log in the admin site, the style of the page of the admin 
panel is well stylized, as it should be.
But in the test that I did in a Windows environment (the same 
configuration), everything is correct, but the page of the administration 
panel does not have any style, why is this? I search in many forums but I 
could not find a solution. Thanks in advance.

-- 
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/c26e722d-69fd-4dd2-9e32-94f451cf8e0f%40googlegroups.com.


Re: Capture URL values in a CBV

2020-04-16 Thread Tim Johnson


On 4/15/20 7:24 PM, Gavin Wiener wrote:

Hey Tim

Hello Gavin: Thank you for your prompt reply.


The bigger question is, what are you trying to achieve?


I gotta know. I'm a retired programmer with 19 years doing CGI. Wrote 
and implemented my own framework. First in C, than C++ then rebol, then 
python.


I really want to know what is going on "under the hood" but I also wish 
to know why those examples, taken from documentation do not work.


I'm building a website with django as an alternative to the original in 
Drupal because I want fine-grained control.


I hope that answers your question.



With the DetailView, fetching the object with the primary key is 
already handled for you, as you've seen the object will already be 
available in the template.


This website is very useful to know which functions are implemented in 
a class-based view, and which variables are available.


http://ccbv.co.uk/


Thanks for the link. Will study it after finishing my coffee.


On Thursday, April 16, 2020 at 8:26:00 AM UTC+8, tim042849 wrote:

using django.VERSION (2, 1, 5, 'final', 0) with

python 3.7.2 on ubuntu 16.04

Given the URL pattern below:

path('', ArticleDetailView.as_view(), name='article_detail'),

And the view as below:

class ArticleDetailView(DetailView):
    model = Article
    template_name = 'article_detail.html'
    login_url = 'login'

I can access the variable pk from a template as

article.pk 

But I don't know how to access the pk variable from the view itself.

Adding the get_queryset method to the view doesn't work

example

def get_queryset(self):
    print(self.kwargs["pk"])

results in

'NoneType' object has no attribute 'filter' Trying def
get_object(self): queryset =
self.filter_queryset(self.get_queryset()) obj =
queryset.get(pk=self.kwargs['pk']) return obj results in
'ArticleDetailView' object has no attribute 'filter_queryset'
Please advise - pretty basic for django, new to me :) thanks

-- 
Tim

tj49.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 django-users+unsubscr...@googlegroups.com 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/39595843-0a01-4ffb-95b9-46d2d3c442e3%40googlegroups.com 
.


--
Tim
tj49.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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/52390ecd-3748-6c96-3a1b-a2d671322336%40akwebsoft.com.


Re: Models as choices

2020-04-16 Thread shreehari Vaasistha L
i get this error when trying in your way:

Cannot assign "2": "User.highest_degree" must be a "Degree" instance.

On Thursday, April 16, 2020 at 5:31:07 PM UTC+5:30, Gavin Wiener wrote:
>
> Couldn't the User just have a ForeignKey on countries?
>
> On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L 
> wrote:
>>
>> how can i use model x values as choices for model y ?
>>
>> for eg:
>> class countries(models.Model):
>>  country = models.CharField(max_length=200)
>>
>>  def __str__(self):
>>  return self.country 
>>
>> class User(AbstractUser):
>>  """User model."""
>>
>>  username = None
>>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
>> Name") 
>>  country_choices = models.CharField(choices=countries
>>
>

-- 
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/c7031af8-272d-4fe5-b13a-406e0162385e%40googlegroups.com.


Re: Models as choices

2020-04-16 Thread Gavin Wiener
If you're serializing as JSON, that primary key is literally just integer 
then, and the foreign key relationship requires an instance of that foreign 
key. So you'll need to fetch an instance of the object first.

I've had this issue before, that's how I resolved it.

On Friday, April 17, 2020 at 1:51:05 PM UTC+8, shreehari Vaasistha L wrote:
>
> i get this error when trying in your way:
>
> Cannot assign "2": "User.highest_degree" must be a "Degree" instance.
>
> On Thursday, April 16, 2020 at 5:31:07 PM UTC+5:30, Gavin Wiener wrote:
>>
>> Couldn't the User just have a ForeignKey on countries?
>>
>> On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L 
>> wrote:
>>>
>>> how can i use model x values as choices for model y ?
>>>
>>> for eg:
>>> class countries(models.Model):
>>>  country = models.CharField(max_length=200)
>>>
>>>  def __str__(self):
>>>  return self.country 
>>>
>>> class User(AbstractUser):
>>>  """User model."""
>>>
>>>  username = None
>>>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
>>> Name") 
>>>  country_choices = models.CharField(choices=countries
>>>
>>

-- 
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/c563335e-cd3f-4204-9aec-6c098dc3a525%40googlegroups.com.