Sunday, May 31, 2020

Re: AttributeError when returning post.title in a comment model

Try '{0}-{1}'.format(var1, var2)

Check in the console in what line it's throwing the attribute error

Rewards 

El vie., 29 de mayo de 2020 5:10 p. m., Ahmed Khairy <ahmed.heshameldin@gmail.com> escribió:

I was working on a comment section for post and was getting an AttributeError when I return return '{}-{}'.format(self.post.title, str(self.user.username)) in the comment model

I am trying to link users and posts to the comment I am getting the same error

Here is the Models.py

class Comment(models.Model):      post = models.ForeignKey(Post, on_delete=models.CASCADE)      user = models.ForeignKey(User, on_delete=models.CASCADE)      content = models.TextField(max_length=160)      timestamp = models.DateTimeField(auto_now_add=True)        def __str__(self):          return '{}-{}'.format(self.post.title, str(self.user.username))  

Here is the views.py:

class PostDetailView(DetailView):      model = Post      template_name = "post_detail.html"        def get_context_data(self, *args, **kwargs):          context = super(PostDetailView, self).get_context_data()          post = get_object_or_404(Post, slug=self.kwargs['slug'])          comments = Comment.objects.filter(post=post).order_by('-id')          total_likes = post.total_likes()          liked = False          if post.likes.filter(id=self.request.user.id).exists():              liked = True            if self.request.method == 'POST':              comment_form = CommentForm(self.request.POST or None)              if comment_form.is_valid():                  content = self.request.POST.get('content')                  comment = Comment.objects.create(                      post=post, user=request.user, content=content)                  comment.save()                  return HttpResponseRedirect("post_detail.html")          else:              comment_form = CommentForm()            context["total_likes"] = total_likes          context["liked"] = liked          context["comments"] = comments          context["comment_form"] = comment_form          return context      class PostCommentCreateView(LoginRequiredMixin, CreateView):      model = Comment      form_class = CommentForm  

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9e84bb03-ca66-4517-ab34-8d723a457b9f%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHRQUHki1Fk2s1a9ws4vB7yhfaLFhyboOVwvPSSVG87BSo0%3DtA%40mail.gmail.com.

Re: Can You please help me out!!!

Boolean field on notification model that change status when click or view the notification , this perhaps need an asynchronous task with jQuery or celery

Rewards 

El vie., 29 de mayo de 2020 9:28 p. m., meera gangani <meeragangani12@gmail.com> escribió:
I Want to implement Mark all a read in notification!!
So What should i do!!
Can you explain me a little bit of this!

On Sat, May 30, 2020 at 8:46 AM meera gangani <meeragangani12@gmail.com> wrote:
Thank you So much for helping me out!!
Thanks a lot

Meera Gangani

On Fri, May 29, 2020 at 5:08 PM Sencer Hamarat <sencerhamarat@gmail.com> wrote:
Hi Meera,

You have only one record because of you are using .latest() method in the query.

If you want to last 3 or 4 object ordered by descending date, you should write queryset like this:

notifications = Notification.objects.all().order_by('-date')[0:x]  # The 'x' could be 3 or 4 by your choice.

An pass the notifications to request context in 'render_to_response' call. {'notifications': notifications}

The you have to iterate notifications in template via for loop. For example;

{% for notification in notifications %}
<div>notification.title</div>
<div>notification.message</div>
<div>notification.date</div>
{% endfor %}

Saygılarımla,
Sencer HAMARAT



On Fri, May 29, 2020 at 1:59 PM meera gangani <meeragangani12@gmail.com> wrote:
i want to fetch last 3 records for notification!!
But I only fetch last 1 record.

Can you please help me out!!!
Can i use filters??

And my model fields are:
title=
message=
date=

And i want to fetch last 3-4 records

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANaPPPJVprm5gE0FNFWqPDGdW_ciq15JQXLmjVHinJkHPwRdqQ%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACp8TZh3iD4M2%3Ddq4NOrPTpOzAYCFxx_kduS6%2BK%2BEG2kPDFkYA%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANaPPPLnRv2matia%2B6Xm9j0cSoNHYWnn8HMt08ojmqxQOrXvCg%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHRQUH%3DZniCZo8YLG%3DG%3DbXQDJddqQ1%2BGGLFnFx4A_jrtLerjeg%40mail.gmail.com.

Re: keras

sorry I was using python 3.7.4 32bit and it required 64 , now it worked for me 

Le lundi 1 juin 2020 01:13:54 UTC+1, Franck Tchouanga a écrit :
Which version are you trying to install

On Mon, Jun 1, 2020, 00:39 HJ <hajar...@gmail.com> wrote:
hello guys hope u r doing well 

I want to use keras but I face the error like there is no module named tensorflow when I try to install it I face this error : 

*ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow*

do you have any suggestions ?

--
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/04e69dab-2560-47ae-8c52-004b61ebd9ed%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ec930528-b86f-4a9f-9b7e-54a0ea535dc4%40googlegroups.com.

Re: Ajax and Django and jQuery - .attr()

Hello!

To answer the question about template tags in javascript, i.e. $.post("{% url 'upvote' %}", {answer_id:answerid}) I

This works when your js is written in the template, as you have it, but if you ever want to move that JavaScript into a separate .js file, it will break. That's because right now your file is being run through the Django templating engine, but a stand-alone js file wouldn't be. What I usually do is put a data attribute on a convenient element and then get it in the way that Stephen suggests below.

So I would have <i class="upvote" data-answer-id="{{answer.id}}" data-url="{% url 'upvote' %}", {answer_id:answerid"}>&#8593</I> in my html, and then in my javascript, something like this:

$(".upvote").click( function () {
            let answerid = $(this).data("answer-id");
            console.log(answerid);
            $.post($(this).data("url'), {answer_id:answerid});
});


Good luck, hope this helps!
Melinda

On May 31, 2020, at 1:26 PM, Stephen J. Butler <stephen.butler@gmail.com> wrote:

This isn't a jQuery issue, it's a JavaScript/ECMAScript issue. When you use the "arrow function" style like "() => { ...code... }" then certain variables are not bound into the function contact, including "this". https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

To get "this" inside your event handler you need to use "function () { code... }".

$(".upvote").click( function () {
            let answerid = $(this).attr("answer-id");
            console.log(answerid);
            $.post("{% url 'upvote' %}", {answer_id:answerid});
});

But also, it's bad bad form to define your own attribute names on HTML. Use the "data-answer-id" attribute name to do this, and in your code access it with $(this).data("answer-id").

On Sun, May 31, 2020 at 2:19 PM Jan Gregorczyk <jnk.gregorczyk@gmail.com> wrote:
I have a problem with Ajax and Django templates. I'm new to Ajax and jquery.
Console log at the end of the script prints undefined. I don't know why let answerid = $(this).attr("answer-id"); doesn't extract attribute from this line: <i class="upvote" answer-id="{{answer.id}}">&#8593</i>
I also want to know if using template tags in javascript scripts like here $.post("{% url 'upvote' %}", {answer_id:answerid}) is a good idea.


{% extends 'base.html' %}
{% block title %}{{question.title|truncatechars:52}}{% endblock %}
{% block content %}
<h1>{{question.title}}</h1>
<p>{{question.content}}</p>
{% for answer in question.answers.all %}
<h3>{{answer.author}}</h3>
<p>{{answer.content}}</p>
<p>
<i class="upvote" answer-id="{{answer.id}}">&#8593</i>
{{answer.votes.count}}
<i class="downvote" answer-id="{{answer.id}}">&#8595</i>
</p>
{% endfor %}
<form method="POST" action="{% url 'answer' question.id %}">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Odpowiedz">
</form>
{% endblock %}
{% block javascript %}
{% load static %}
<script>
//upvote and downvote script
var csrftoken = window.Cookies.get('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
$(".upvote").click( () => {
let answerid = $(this).attr("answer-id");
console.log(answerid);
$.post("{% url 'upvote' %}", {answer_id:answerid});
});
</script>
{% endblock %}

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aa129ea5-dd3d-402f-a297-796b408e8217%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAD4ANxVDepam-GZ_nOBKoD9fff7aPE9ic5Et-VxJvw85vqEQrQ%40mail.gmail.com.

Re: keras

Which version are you trying to install

On Mon, Jun 1, 2020, 00:39 HJ <hajarbenjat@gmail.com> wrote:
hello guys hope u r doing well 

I want to use keras but I face the error like there is no module named tensorflow when I try to install it I face this error : 

*ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow*

do you have any suggestions ?

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/04e69dab-2560-47ae-8c52-004b61ebd9ed%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANRJ%3D3mwFHof0rUMyb-jCxKQN0CV09vi-1TBa1sOtW6N67n27g%40mail.gmail.com.

keras

hello guys hope u r doing well 

I want to use keras but I face the error like there is no module named tensorflow when I try to install it I face this error : 

*ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow*

do you have any suggestions ?

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/04e69dab-2560-47ae-8c52-004b61ebd9ed%40googlegroups.com.

Re: Ajax and Django and jQuery - .attr()

This isn't a jQuery issue, it's a JavaScript/ECMAScript issue. When you use the "arrow function" style like "() => { ...code... }" then certain variables are not bound into the function contact, including "this". https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

To get "this" inside your event handler you need to use "function () { code... }".

$(".upvote").click( function () {
            let answerid = $(this).attr("answer-id");
            console.log(answerid);
            $.post("{% url 'upvote' %}", {answer_id:answerid});
});

But also, it's bad bad form to define your own attribute names on HTML. Use the "data-answer-id" attribute name to do this, and in your code access it with $(this).data("answer-id").

On Sun, May 31, 2020 at 2:19 PM Jan Gregorczyk <jnk.gregorczyk@gmail.com> wrote:
I have a problem with Ajax and Django templates. I'm new to Ajax and jquery.
Console log at the end of the script prints undefined. I don't know why let answerid = $(this).attr("answer-id"); doesn't extract attribute from this line: <i class="upvote" answer-id="{{answer.id}}">&#8593</i>
I also want to know if using template tags in javascript scripts like here $.post("{% url 'upvote' %}", {answer_id:answerid}) is a good idea.


{% extends 'base.html' %}
{% block title %}{{question.title|truncatechars:52}}{% endblock %}
{% block content %}
<h1>{{question.title}}</h1>
<p>{{question.content}}</p>
{% for answer in question.answers.all %}
<h3>{{answer.author}}</h3>
<p>{{answer.content}}</p>
<p>
<i class="upvote" answer-id="{{answer.id}}">&#8593</i>
{{answer.votes.count}}
<i class="downvote" answer-id="{{answer.id}}">&#8595</i>
</p>
{% endfor %}
<form method="POST" action="{% url 'answer' question.id %}">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Odpowiedz">
</form>
{% endblock %}
{% block javascript %}
{% load static %}
<script>
//upvote and downvote script
var csrftoken = window.Cookies.get('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
$(".upvote").click( () => {
let answerid = $(this).attr("answer-id");
console.log(answerid);
$.post("{% url 'upvote' %}", {answer_id:answerid});
});
</script>
{% endblock %}

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aa129ea5-dd3d-402f-a297-796b408e8217%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAD4ANxVDepam-GZ_nOBKoD9fff7aPE9ic5Et-VxJvw85vqEQrQ%40mail.gmail.com.

Ajax and Django and jQuery - .attr()

I have a problem with Ajax and Django templates. I'm new to Ajax and jquery.
Console log at the end of the script prints undefined. I don't know why let answerid = $(this).attr("answer-id"); doesn't extract attribute from this line: <i class="upvote" answer-id="{{answer.id}}">&#8593</i>
I also want to know if using template tags in javascript scripts like here $.post("{% url 'upvote' %}", {answer_id:answerid}) is a good idea.


{% extends 'base.html' %}
{% block title %}{{question.title|truncatechars:52}}{% endblock %}
{% block content %}
<h1>{{question.title}}</h1>
<p>{{question.content}}</p>
{% for answer in question.answers.all %}
<h3>{{answer.author}}</h3>
<p>{{answer.content}}</p>
<p>
<i class="upvote" answer-id="{{answer.id}}">&#8593</i>
{{answer.votes.count}}
<i class="downvote" answer-id="{{answer.id}}">&#8595</i>
</p>
{% endfor %}
<form method="POST" action="{% url 'answer' question.id %}">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Odpowiedz">
</form>
{% endblock %}
{% block javascript %}
{% load static %}
<script src="https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js"></script>
<script>
//upvote and downvote script
var csrftoken = window.Cookies.get('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
$(".upvote").click( () => {
let answerid = $(this).attr("answer-id");
console.log(answerid);
$.post("{% url 'upvote' %}", {answer_id:answerid});
});
</script>
{% endblock %}

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aa129ea5-dd3d-402f-a297-796b408e8217%40googlegroups.com.

Re: How to make Custom User Registration and Login

It's better to make a separate app for users. You can call the app users or account. Create a form.py file in your users app. Then create a CustomUser class that inherits from either AbstractUser or AbstractBaseUser (check out the difference between the two). Then you can define the fields you want to use.
Create UserCreationForm subsequently.

Create a folder called registration inside your templates folder and create your login.html there

You must update your settings with
AUTH_USER_MODEL = 'users.CustomUser'

LOGIN_URL = 'login' Note, login here is the name you gave your login url.

On Sun, May 31, 2020, 3:37 PM Abhi Mathew <abhimathew1999@gmail.com> wrote:
I don't how familiar you are with Django but this post will help you anyhow!

On Wednesday, May 6, 2020 at 3:39:29 PM UTC+5:30, Anubhav Madhav wrote:
I am new to Django. I need to make a custom sign up and log in page. Because, during Sign Up, I also want to get User's Address and Contact Number. In Django's 'User' module, it isn't supported. So, how can I make a custom sign up and sign in page. Please Help!!

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/42f04b63-6d5f-473e-9526-a6fe906ceef8%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALcuGNvPgG5Mcg%2BEj0bLu_%3DRjLQZY8E%2Btu2N8cv7enXosUa5_Q%40mail.gmail.com.

Re: Need Dashboard in Django Admin only

PS - Should be "Django REST Framework" ( https://github.com/encode/django-rest-framework )
 
PPS - Please don't use pie charts, especially 3D, for your visuals ( https://www.businessinsider.com/pie-charts-are-the-worst-2013-6?IR=T )
 
On Sunday, 31 May 2020 17:05:16 UTC+2, Derek wrote:
There are numerous ways to design a front-end dashboard; this a highly contested domain on the web!  

Just some examples, using Django + various other tech are:

https://morioh.com/p/88d6fc714f52

I suggest you look at delivering data from the back end (your Django models) with Django REST Framer (rather than hand-coded JSON); its takes a bit of work to setup but its the most flexible going forward in terms of future needs. e.g.

P.S. Looks like you  are trying to support work for COVID-19 - all the best with that!


On Saturday, 30 May 2020 17:08:23 UTC+2, Balaji wrote:
Hi


If I want to generate such Dashboard in Djano Admin only

Can anyone suggest pypi package..

Any Sample code is available on git.

2 situation 

1. Only for 1 model

2 For 2 model connected by Foreign Key relationships 




--
Mr Shetty Balaji
Asst. Prof.
IT Department
SGGS I&T
Nanded. My. India

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/46daa73b-afa8-46d1-b6c9-7420f9edce60%40googlegroups.com.

Re: Need Dashboard in Django Admin only

There are numerous ways to design a front-end dashboard; this a highly contested domain on the web!  

Just some examples, using Django + various other tech are:

https://morioh.com/p/88d6fc714f52

I suggest you look at delivering data from the back end (your Django models) with Django REST Framer (rather than hand-coded JSON); its takes a bit of work to setup but its the most flexible going forward in terms of future needs. e.g.

P.S. Looks like you  are trying to support work for COVID-19 - all the best with that!


On Saturday, 30 May 2020 17:08:23 UTC+2, Balaji wrote:
Hi


If I want to generate such Dashboard in Djano Admin only

Can anyone suggest pypi package..

Any Sample code is available on git.

2 situation 

1. Only for 1 model

2 For 2 model connected by Foreign Key relationships 




--
Mr Shetty Balaji
Asst. Prof.
IT Department
SGGS I&T
Nanded. My. India

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8415ab3f-f1da-4380-b29e-499a1fc9a803%40googlegroups.com.