These are chat archives for django/django

11th
Jul 2017
Anish Shrestha
@annshress
Jul 11 2017 05:22
@LuffyKing jQuery :smile: afaik
@Dragonwarrior47 did you do it? any progress?
Devndra Ghimire
@horrormyth
Jul 11 2017 05:28
How do we specify explicit update_fields for form save method including foreign key ?
Anish Shrestha
@annshress
Jul 11 2017 06:10
Devndra Ghimire
@horrormyth
Jul 11 2017 06:56
Thanks @annshress
Kanhaiya Lal
@Dragonwarrior47
Jul 11 2017 09:13
@annshress no that is not helping
Anish Shrestha
@annshress
Jul 11 2017 09:16
Ok. Share with us, if you solve it.
Kanhaiya Lal
@Dragonwarrior47
Jul 11 2017 09:28
@annshress right now I can only group the result for 1 hour interval , and I have shared the code
data = (
XyzModel.objects
.extra({"day": "date_trunc('hour',violation_time)"})
.values("day", "type")
.order_by("day")
.annotate(count=Count("id"))
)
Kanhaiya Lal
@Dragonwarrior47
Jul 11 2017 11:52
@annshress I am also able to group by each hour , without using extra key word
data = (
...: XyzModel.objects
...: .annotate(hour=HourTransform("violation_time"))
...: .values('hour')
...: .order_by("hour")
...: .annotate(count=Count("id"))
...: )
but how to group data for every two hour interval
Anish Shrestha
@annshress
Jul 11 2017 13:08
@Dragonwarrior47 I was looking into it for a while. What does HourTransform return? Is it integer between 1 and 24?
Or do you obtain total number of hours
Either way. Maybe be you can take a look at Cast, so that you can divide the hour value by 2 and Cast and then group instead. (Or that was what I was thinking.)
from django.db.models.functions import Cast

... 
.annotate(hour=HourTransform("violation_time")/2)  # <-- /2
.annotate(every_second_hour=Cast('hour', IntergerField()))  # <--- cast to int
.values('every_second_hour')
Anish Shrestha
@annshress
Jul 11 2017 13:16
This way you will have:
hour -> every_second_hour
  1 -> 0
2  -> 1
3 -> 1
4 -> 2
5 -> 2
Or thats what I was thinking. give it a try.
Kanhaiya Lal
@Dragonwarrior47
Jul 11 2017 17:50
@annshress I think it will work , but the problem is I am using django version 1.9 and Cast is not there in django 1.9
karry91
@karry91
Jul 11 2017 20:53
I am doing a blog site project but I am getting this error when inside my site '' Enter a valid 'slug' consisting of letters, numbers,underscores or hyphens"
somebody please help
?
Miracle Ayodele
@iammiracle
Jul 11 2017 21:28
hi everyone, i am having an issues on django with javascript
{% for i in range %}
                                        <button class="btn btn-success" name="{{ i }}" id="guess" value="{{ i }}{{ forloop.counter }}" onclick="transferField(this.value)">{{ i }} </button>
                                    {% endfor %}
that snippet creates numbers of buttons depending on the range
but the issue i have is, all buttons have the same id, and its making it difficult for me to treat each button differently
because as it is, al buttons share the same id
i will appreciate any ideas to this challenge, thanks
Nnamdi
@nnamdiib
Jul 11 2017 21:35
'''
@koderNeptune
Miracle Ayodele
@iammiracle
Jul 11 2017 21:37
i'm with you @nnamdiib, whats your input?
Nnamdi
@nnamdiib
Jul 11 2017 21:38
@koderNeptune You can add a digit to the id section of the button tag via the for loop
'''
{% for i in range %}
<button class="btn btn-success" name="{{ i }}" id="guess"+{{ i }} value="{{ i }}{{ forloop.counter }}" onclick="transferField(this.value)">{{ i }} </button>
{% endfor %}
'''
{% for i in range %}
<button class="btn btn-success" name="{{ i }}" id="guess"+{{ i }} value="{{ i }}{{ forloop.counter }}" onclick="transferField(this.value)">{{ i }} </button>
{% endfor %}
Sorry for the mess, I forgot how to format code snippets on gitter.
@koderNeptune What do you think?
Miracle Ayodele
@iammiracle
Jul 11 2017 21:41
Sorry for the mess, I forgot how to format code snippets on gitter.
no problem about that
id="guess" + {{ i }}
seems not to be allowed @nnamdiib
and moreover the javascript snippet
$(document).on("click", "#guess", function(){
            //do something
          var color = clicked ? '#FF8E2B' : '#27AE60';
               $(this).css('background-color', color);
                clicked = !clicked;
        });
id="guess" + {{ i }}
i haved changed it to id = "guess{{ i }}"
Nnamdi
@nnamdiib
Jul 11 2017 21:48
Oh silly me. That should work now.
Miracle Ayodele
@iammiracle
Jul 11 2017 21:48
javascript wont accept that
Nnamdi
@nnamdiib
Jul 11 2017 21:49
What do you mean by "Won't accept"
For the JQuery portion try and use something else to target the buttons other than ID
Miracle Ayodele
@iammiracle
Jul 11 2017 21:50
@nnamdiib like what
what i am trying to achieve is when i button is clicked, the button is in range of 1-100
so when 1 is clicked it changes color , when 6 is clicked, it changes color,also when uncliked
so i feel id willl be the best
but if you have a cool opinion, i will try it out
Nnamdi
@nnamdiib
Jul 11 2017 21:53
Hmm I see.
It seems like your original question of how to make each ID unique has been resolved
What we're talking about now is more to do with HTML and JS and less of Django.
Miracle Ayodele
@iammiracle
Jul 11 2017 21:54
yeah
Nnamdi
@nnamdiib
Jul 11 2017 21:54
So let's not derail from the topic of this chatroom. Maybe a private chat?
Miracle Ayodele
@iammiracle
Jul 11 2017 21:55
ok,i understand thanks @nnamdiib