Re: Is it possible to save children before parents?

2017-02-14 Thread Mike Dewhirst

On 15/02/2017 6:01 PM, Antonis Christofides wrote:

Hi,

the problem you are having has some resemblance to a problem I once faced,
http://stackoverflow.com/questions/33500336/checking-integrity-of-manytomanyfield.
It's not the same; my problem was to check the integrity of the "children",
whereas you seem to have a problem with the admin. However it keeps coming to me
during the thread so I thought I'd mention it.


Antonis

AFAICT the problem is really not a problem at all. It is data integrity 
protection which I should not be trying to circumvent. The save, plus 
any pre-save and post-save activity takes place in a single transaction 
involving the main record and all children. Only when that transaction 
is committed and succeeds is the database actually updated. That says 
the children and master are updated more or less simultaneously.


I think it has to be done in two transactions. Two saves.

Hence, I need to find a way of updating the children in a first 
transaction which is committed and updates the database before the 
master can find the new proportion values when it goes looking during 
the next save (or second transaction).


If I wasn't using the admin, I could do that in my own forms without too 
much trouble.


Or javascript might look at the in-browser children values and change 
the sum in the master record in the browser. At that point a save puts 
the precalculated sum into the database at the same time as the changed 
values in the children records.


I looked at javascript once and nearly vomited. We'll save() twice until 
we get some funding then I'll hire a js person to let me off the hook ;-)


Thanks again

Cheers

Mike



Regards,

Antonis

Antonis Christofides
http://djangodeployment.com



On 02/15/2017 06:14 AM, Mike Dewhirst wrote:

Logically, this is a tail-chasing exercise. The total sum of ingredient
proportions is calculated from a query of ingredients. It runs when saving the
mixture. It can only get previously saved data.

Aaaargh!!!

I forgot to tell you that the ingredients are inlines and proportions get
saved when the mixture is saved.

If there is a way to save inlines *before* saving the main record the problem
might be solved.

Otherwise the only solution I can see is to inject some javascript into the
Admin to read the proportion values and update the sum field just prior to
saving the lot.

At this point I think a double save is easier than js

Thanks again

Mike

On 14/02/2017 4:16 PM, Mike Dewhirst wrote:

Derek, Antonis, Ludovic and Melvyn

I've got a lot happening in the code because chemical mixtures and safety
regulations are complex. I will attempt to radically simplify it in a new
minimal project and prove/disprove things and report back under this thread.

Many thanks for the suggestions

Much appreciated

Mike

On 14/02/2017 12:14 PM, Melvyn Sopacua wrote:

P.S. I left two bugs in there, for now I'll leave them in as an exercise for
the reader.

--

Melvyn Sopacua

--
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 post to this group, send email to django-users@googlegroups.com
.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/10404615.9y43U2G7Fx%40devstation
.

For more options, visit https://groups.google.com/d/optout.


--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/36fb9b12-5bb9-3952-951a-b884e2d29329%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Is it possible to save children before parents?

2017-02-14 Thread Antonis Christofides
Hi,

the problem you are having has some resemblance to a problem I once faced,
http://stackoverflow.com/questions/33500336/checking-integrity-of-manytomanyfield.
It's not the same; my problem was to check the integrity of the "children",
whereas you seem to have a problem with the admin. However it keeps coming to me
during the thread so I thought I'd mention it.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com



On 02/15/2017 06:14 AM, Mike Dewhirst wrote:
> Logically, this is a tail-chasing exercise. The total sum of ingredient
> proportions is calculated from a query of ingredients. It runs when saving the
> mixture. It can only get previously saved data.
>
> Aaaargh!!!
>
> I forgot to tell you that the ingredients are inlines and proportions get
> saved when the mixture is saved.
>
> If there is a way to save inlines *before* saving the main record the problem
> might be solved.
>
> Otherwise the only solution I can see is to inject some javascript into the
> Admin to read the proportion values and update the sum field just prior to
> saving the lot.
>
> At this point I think a double save is easier than js
>
> Thanks again
>
> Mike
>
> On 14/02/2017 4:16 PM, Mike Dewhirst wrote:
>> Derek, Antonis, Ludovic and Melvyn
>>
>> I've got a lot happening in the code because chemical mixtures and safety
>> regulations are complex. I will attempt to radically simplify it in a new
>> minimal project and prove/disprove things and report back under this thread.
>>
>> Many thanks for the suggestions
>>
>> Much appreciated
>>
>> Mike
>>
>> On 14/02/2017 12:14 PM, Melvyn Sopacua wrote:
>>>
>>> P.S. I left two bugs in there, for now I'll leave them in as an exercise for
>>> the reader.
>>>
>>> -- 
>>>
>>> Melvyn Sopacua
>>>
>>> -- 
>>> 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 post to this group, send email to django-users@googlegroups.com
>>> .
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/10404615.9y43U2G7Fx%40devstation
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/584a259c-16b5-fbb4-a3b6-f75c077b9f03%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it possible to save children before parents?

2017-02-14 Thread Mike Dewhirst
Logically, this is a tail-chasing exercise. The total sum of ingredient 
proportions is calculated from a query of ingredients. It runs when 
saving the mixture. It can only get previously saved data.


Aaaargh!!!

I forgot to tell you that the ingredients are inlines and proportions 
get saved when the mixture is saved.


If there is a way to save inlines *before* saving the main record the 
problem might be solved.


Otherwise the only solution I can see is to inject some javascript into 
the Admin to read the proportion values and update the sum field just 
prior to saving the lot.


At this point I think a double save is easier than js

Thanks again

Mike

On 14/02/2017 4:16 PM, Mike Dewhirst wrote:

Derek, Antonis, Ludovic and Melvyn

I've got a lot happening in the code because chemical mixtures and 
safety regulations are complex. I will attempt to radically simplify 
it in a new minimal project and prove/disprove things and report back 
under this thread.


Many thanks for the suggestions

Much appreciated

Mike

On 14/02/2017 12:14 PM, Melvyn Sopacua wrote:


P.S. I left two bugs in there, for now I'll leave them in as an 
exercise for the reader.


--

Melvyn Sopacua

--
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 post to this group, send email to django-users@googlegroups.com 
.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/10404615.9y43U2G7Fx%40devstation 
. 


For more options, visit https://groups.google.com/d/optout.




--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/31888677-5dcb-42d9-f13c-a5ea67eb5f27%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Pagination is not showing and also not working

2017-02-14 Thread Kazi Atik


On Monday, February 13, 2017 at 1:03:23 AM UTC+5:30, Kazi Atik wrote:
>
> here is my views/
>
> from django.contrib.auth.models import User
>
> from django.core.paginator import Paginator,EmptyPage, PageNotAnInteger
> from friends.models import Friendship,UserProfile
> from django.http import HttpResponse, HttpResponseRedirect, Http404
> from django.shortcuts import render
>
>
> def dashboard(request):
> if request.method == "GET":
> if request.user.is_authenticated():
> userp=UserProfile.objects.filter(user=request.user)
> return render(request, 'dashboard.html', context={ "user": 
> request.user, "userslist" : 
> User.objects.all(),"userprofile":userp,"friendshiplist": 
> Friendship.objects.filter(user1=request.user)})
> elif request.user.is_anonymous():
> return HttpResponse('Hi Guest. Please login to view your 
> dashboard Login')
> elif request.method=="POST":
> raise Http404("dashboard does not support post")
>
> def listing(request):
> users_list = User.objects.all()
> page = request.GET.get('page', 1)
>
> paginator = Paginator(users_list, 3)
> try:
> user_list = paginator.page(page)
> except PageNotAnInteger:
> # If page is not an integer, deliver first page.
> user_list = paginator.page(1)
> except EmptyPage:
> # If page is out of range (e.g. ), deliver last page of results.
> user_list = paginator.page(paginator.num_pages)
>
> return render(request, 'dashboard.html', {'users': user_list})
>
>
> tempalates/
>
>
> 
> 
> People you may know
> 
> Request
> 
>
>  {% for myuser in userslist %}
>  
>
>
>
>{{ myuser.username }}
>
>
> Add
>
>  
>  {% endfor %}
>
>  
>{% if users.has_previous %}
>  
>{% else %}
>  
>{% endif %}
>{% for i in users.paginator.page_range %}
>  {% if users.number == i %}
>{{ i }}  class="sr-only">(current)
>  {% else %}
>{{ i }}
>  {% endif %}
>{% endfor %}
>{% if users.has_next %}
>  
>{% else %}
>  
>{% endif %}
>  
>
> 
>
>
>
> 
>
> i am trying to paginate this but not getting any result
>
>
> please help me 
>
>
> whatsapp-8867203481
>
>
>
>
> please help me on this code
>
>
>
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7d582ad8-20bf-44c7-a724-79dfbb565d19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Check if all boolean values are the same (database)

2017-02-14 Thread Shawn Milochik
I'd go with form validation -- you shouldn't allow a Purchase to be added
to a transaction if a Purchase with a conflicting status is already in
there, nor should a Purchase be able to be modified if it's in a
transaction with another Purchase.

Then you never have to check whether a transaction is valid. The models
pasted don't give the complete picture of the relationship, but garbage in,
garbage out, so just don't allow them to exist in the first place.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOzwKwEOBTjZmAwwK_a7jTD1jyW0%2BVmeuSEVgdcQCNG7ts37Rw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Check if all boolean values are the same (database)

2017-02-14 Thread Victor Porton
# May contain several purchases
class Transaction(models.Model):
name = models.CharField(null=True)

class Purchase(models.Model):
bundle = models.ForeignKey(Transaction, null=True)
recurring = models.BooleanField(default=False)

For a given transaction, all its purchases must either all be recurring
 or all non-recurring.

What is the best way to check it (and throw an exception if in a
transaction there are both non-recurring and recurring purchases)?

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1487113329.20585.1.camel%40narod.ru.
For more options, visit https://groups.google.com/d/optout.


Is it possible to Atomically check limit and Increment/decrement a counter field in multiple tables ?

2017-02-14 Thread sarvi
I have 2 tables Cluster and Node, each having a volume_limit and 
volume_count column in it.
To atomically check and increment the volume count for a Cluster and Node I 
do the following
updated = Cluster.objects.filter(id=cluster_id, 
volume_count__lt==F('volume_limit')).update(volume_count = 
F('volume_count')+1)
if not updated:
raise Validation('limit reached ..')
updated = Node.objects.filter(id=node_id, 
volume_count__lt==F('volume_limit')).update(volume_count = 
F('volume_count')+1)
if not updated:
Cluster.objects.filter(id=cluser_id).update(volume_count = 
F('volume_count')-1)
raise Validation('limit reached ..')


I am wondering if there is way to do both of this atomically?

Basically I want to 
   1. create a query for Cluster, Node, etc, N such objects/tables queries, 
that each filter match one row by pk and volume_count__lt=F('volume_count')
   2. Check that the union of all these queries translates to exactly N 
objects, one for each Object/Table. i.e. the counts are within limit for 
each object/table
   3. Do a volume_count=F('volume_count')+1 for all those objects/table 
together.

How do I do this?

Thanks,
Sarvi

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f47d5d55-d97a-4e63-85b2-4740e56c10ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django documentation tutorial part 1

2017-02-14 Thread Alexis Carmona
Hey, I checked your code on githubt and i think that you missed yo import 
your views in your urls file

El lunes, 6 de febrero de 2017, 17:12:30 (UTC-4), Philip escribió:
>
> Hello,
>
> I am working through the tutorial included with the django documentation, 
> and I am confused as to why my url is not working. I have the most recent 
> versions of django and python (the ones that the tutorial says to use) and 
> I believe my file structure is correct, you can see it on  
> https://github.com/philipkiely/docexample to verify. However, I get a 404 
> error when I try localhost:8000/polls/, where the documentation tutorials 
> says that I should be seeing the page that I built.
>
> Thank you,
>
> Philip
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/31b1f171-cf30-49dd-9c06-02d5d4f691de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Saving Data in Multiple Selected Checkbox for Voting System

2017-02-14 Thread Genaro Lubong
thank you so much, it helped me a lot, gonna few more for further errors, I
may encounter, thanks a lot
On Feb 14, 2017 9:48 PM, "ludovic coues"  wrote:

> You provided vote from views.py but vote redirect the user. It does
> not use the provided voting.html template.
>
> Also, in my opinion, they are way too many if and for. You have three,
> nested, loops. And you are using only a subset of each loop data.
> I assume position.organization is a foreign key. So you should be able
> to do "{% for position in organization.position_set %}" instead of "{%
> if all_position %}{% for position in all_position %}{% if organization
> == position.organization %}"
> Just the same, you should have a position.candidate_set, with the list
> of all candidate in a position.
>
> I hope that help.
> These information come from the models.ForeignKey documentation [1]
> which point to the queries documentation [2]
>
> [1] https://docs.djangoproject.com/en/1.10/ref/models/fields/
> #django.db.models.ForeignKey.related_name
> [2] https://docs.djangoproject.com/en/1.10/topics/db/queries/
> #backwards-related-objects
>
> 2017-02-14 12:35 GMT+01:00 Genaro Lubong :
> > so I need to provide it? I am using def views for the template
> >
> > On Feb 10, 2017 7:14 PM, "ludovic coues"  wrote:
> >>
> >> You didn't provide the view making use of that template
> >>
> >> 2017-02-10 10:49 GMT+01:00 Genaro Lubong :
> >> > please help me guys
> >> >
> >> >
> >> > On Feb 8, 2017 12:33 AM, "Genaro Lubong"  wrote:
> >> >
> >> > Hello, newbie here, I am currently making our capstone project as a
> >> > requirement to our course subject, and it is a major subject, while I
> >> > was in
> >> > the part of retreiving the selected candidates, I was not about to
> >> > iterate
> >> > the vote for those selected on the upper part, just the last selected
> >> > item/object/candidate, and since it is the major objective of our
> >> > project,
> >> > and I am stucked with it and our team will be screwed if I didn't
> >> > finished
> >> > it As Soon As Possible, here are my codes:
> >> >
> >> >
> >> > #views.py
> >> >
> >> > def vote(request):
> >> >  selected_candidate =
> >> > Candidate.objects.get(pk=request.POST.get('candidate'))
> >> >  selected_candidate.totalvotes += 1
> >> >   selected_candidate.save()
> >> >   return redirect('vs:index')
> >> >
> >> > #voting.html
> >> >
> >> > {% if all_candidates %}
> >> >  
> >> >  {% csrf_token %}
> >> >  {% for organization in all_organizations %}
> >> >  {% if all_positions %}
> >> >  {{ organization.organization }}
> >> >  {% for position in all_positions %}
> >> >  {% if organization == position.organization %}
> >> >  {{ position.position }}
> >> >  
> >> >  {% for candidate in all_candidates %}
> >> >  {% if position == candidate.position
> %}
> >> >  
> >> >  
> >> >   class="portfolio-link"
> >> > data-toggle="modal">
> >> >   >> > class="portfolio-hover">
> >> >   >> > class="portfolio-hover-content">
> >> >   >> > type="checkbox" id="candidate{{ forloop.counter }}" class="candidate{{
> >> > position.id }} fa fa-check fa-3x"  name="candidate" value="{{
> >> > candidate.id
> >> > }}" />
> >> >  
> >> >  
> >> >  
> >> >  
> >> >>> > class="portfolio-caption">
> >> >  {{
> >> > candidate.studentid.firstname }} {{ candidate.studentid.middlename }}
> {{
> >> > candidate.studentid.lastname }} {{ candidate.studentid.suffix }}
> >> >   >> > class="text-muted">{{
> >> > candidate.position }} - {{ candidate.party }}
> >> >  
> >> >  
> >> >  
> >> >  {% endif %}
> >> >  {% endfor %}
> >> >  
> >> >  {% endif %}
> >> >  {% endfor %}
> >> >  {% endif %}
> >> >  {% endfor %}
> >> >  
> >> >  
> >> >  
> >> >   
> >> >  {% else %}
> >> >  No Candidates Yet {% endif %}
> >> >
> >> > #models.py
> >> >
> >> > class 

Re: Django documentation tutorial part 1

2017-02-14 Thread Dário Carvalho
I'm seeing your post only know. Sorry. In deed I used 127.0.0.1:8000
without the /polls when I first ran the server. When I tried with the
/polls could finally see the page.

2017-02-07 11:18 GMT-02:00 Gerald Brown :

> Have you tried using "127.0.0.1" instead of "localhost"?  I had a similar
> problem when I used "localhost"
>
> On Tuesday, February 7, 2017 at 5:12:30 AM UTC+8, Philip wrote:
>>
>> Hello,
>>
>> I am working through the tutorial included with the django documentation,
>> and I am confused as to why my url is not working. I have the most recent
>> versions of django and python (the ones that the tutorial says to use) and
>> I believe my file structure is correct, you can see it on
>> https://github.com/philipkiely/docexample to verify. However, I get a
>> 404 error when I try localhost:8000/polls/, where the documentation
>> tutorials says that I should be seeing the page that I built.
>>
>> Thank you,
>>
>> Philip
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/d45I92r6cCo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/19dbc28b-c01e-4398-bd44-d6dd7ce6f329%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN%3Du3dm5qEvycaehu8i5k5kEe4fYPDfeUbwvvM%3DhYA_8ahCwwQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Using postgres ts_rank's normalization parameter in django?

2017-02-14 Thread Thomas Nyberg

Hello,

I've been looking at the documentation on this page:

https://docs.djangoproject.com/en/1.10/ref/contrib/postgres/search/

I am trying to use the postgres ts_rank function as exposed through 
django. The ts_rank function in postgres can be called in (at least) two 
ways:


* ts_rank(tsvector, tsquery)
* ts_rank(tsvector, tsquery, normalization)

The normalization integer is documented here (textsearch for normalization):

https://www.postgresql.org/docs/current/static/textsearch-controls.html

I don't see in the documentation where this is exposed in the django 
side of things. How do I make use of that option?


Thanks for any help and sorry if I'm just blindly missing something 
obvious in the documentation.


Cheers,
Thomas

--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3fb397fc-8c3a-6e8f-19b2-46fd3fabd215%40gmx.com.
For more options, visit https://groups.google.com/d/optout.


BlogEngine2 0.6.5 release

2017-02-14 Thread Etienne Robillard

Hi,

I'm thrilled to announce the release of BlogEngine2 API.

http://isotopesoftware.ca/pub/blogengine2/blogengine2-0.6.5.tar.gz

BlogEngine is a lightweight microblogging API for Django.

Bitbucket page: https://bitbucket.org/tkadm30/blogengine2

Whats new:
- Initial alpha release.
- Require ZODB 3.7.4, libschevo 3.2.8, Django 1.10, and django-hotsauce 
0.6.5.


For more informations: http://isotopesoftware.ca/software/blogengine2/

Best Regards,
Etienne

--
Etienne Robillard
tkad...@yandex.com
http://www.isotopesoftware.ca/

--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/216e25d9-d363-2acc-558e-f0c6d0f9b446%40yandex.com.
For more options, visit https://groups.google.com/d/optout.


Re: Inconsistent types in PostgreSQL RangeFields

2017-02-14 Thread Tim Graham
The documentation says, "All of the range fields translate to psycopg2 
Range objects  in 
python, but also accept tuples as input if no bounds information is 
necessary."

It looks to me like you could initialize the objects using psycopg's Range 
objects to eliminate the need to handle the tuple case. The tests have some 
examples: 
https://github.com/django/django/blob/master/tests/postgres_tests/test_ranges.py

On Tuesday, February 14, 2017 at 8:05:57 AM UTC-5, 
francois-xa...@airinov.fr wrote:
>
> Hello all,
>
> I've been hitting a small annoyance when using the RangeField classes in 
> the PostgreSQL contrib modules : while the value returned by psycopg is a 
> psycopg.extras.Range type, the Django documentation explicitly mentions 
> using tuples when creating and updating model instances.
>
> This means that any method or property that has to process RangeFields 
> must handle both tuples and Range types, which are incompatible.
>
> For example, here is a very simple model :
>
> class MyModel(models.Model):
>
> range = DateTimeRangeField()
>
> def has_started_1(self):
> return self.range.lower() <= timezone.now()
>
> def has_started_2(self):
> return self.range[0] <= timezone.now()
>
> In this naïve implementation, the `has_started_1` method will crash when 
> used like this :
>
> instance = MyModel.objects.create(range=(timezone.now(), 
> timezone.now() + timezone.timedelta(days=5))
> instance.has_started_1()  # Crash
> instance.has_started_2()  # True
>
> ...and the `has_started_2` method will crash with this :
>
> instance = MyModel.objects.last()
> instance.has_started_1()  # True
> instance.has_started_2()  # Crash
>
> How should I handle that better?
>
> Thanks for your help!
> François-Xavier
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/517e880b-17cc-4ef7-a68b-14fcd5ff5a4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Saving Data in Multiple Selected Checkbox for Voting System

2017-02-14 Thread ludovic coues
You provided vote from views.py but vote redirect the user. It does
not use the provided voting.html template.

Also, in my opinion, they are way too many if and for. You have three,
nested, loops. And you are using only a subset of each loop data.
I assume position.organization is a foreign key. So you should be able
to do "{% for position in organization.position_set %}" instead of "{%
if all_position %}{% for position in all_position %}{% if organization
== position.organization %}"
Just the same, you should have a position.candidate_set, with the list
of all candidate in a position.

I hope that help.
These information come from the models.ForeignKey documentation [1]
which point to the queries documentation [2]

[1] 
https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.ForeignKey.related_name
[2] 
https://docs.djangoproject.com/en/1.10/topics/db/queries/#backwards-related-objects

2017-02-14 12:35 GMT+01:00 Genaro Lubong :
> so I need to provide it? I am using def views for the template
>
> On Feb 10, 2017 7:14 PM, "ludovic coues"  wrote:
>>
>> You didn't provide the view making use of that template
>>
>> 2017-02-10 10:49 GMT+01:00 Genaro Lubong :
>> > please help me guys
>> >
>> >
>> > On Feb 8, 2017 12:33 AM, "Genaro Lubong"  wrote:
>> >
>> > Hello, newbie here, I am currently making our capstone project as a
>> > requirement to our course subject, and it is a major subject, while I
>> > was in
>> > the part of retreiving the selected candidates, I was not about to
>> > iterate
>> > the vote for those selected on the upper part, just the last selected
>> > item/object/candidate, and since it is the major objective of our
>> > project,
>> > and I am stucked with it and our team will be screwed if I didn't
>> > finished
>> > it As Soon As Possible, here are my codes:
>> >
>> >
>> > #views.py
>> >
>> > def vote(request):
>> >  selected_candidate =
>> > Candidate.objects.get(pk=request.POST.get('candidate'))
>> >  selected_candidate.totalvotes += 1
>> >   selected_candidate.save()
>> >   return redirect('vs:index')
>> >
>> > #voting.html
>> >
>> > {% if all_candidates %}
>> >  
>> >  {% csrf_token %}
>> >  {% for organization in all_organizations %}
>> >  {% if all_positions %}
>> >  {{ organization.organization }}
>> >  {% for position in all_positions %}
>> >  {% if organization == position.organization %}
>> >  {{ position.position }}
>> >  
>> >  {% for candidate in all_candidates %}
>> >  {% if position == candidate.position %}
>> >  
>> >  
>> >  > > data-toggle="modal">
>> >  > > class="portfolio-hover">
>> >  > > class="portfolio-hover-content">
>> >  > > type="checkbox" id="candidate{{ forloop.counter }}" class="candidate{{
>> > position.id }} fa fa-check fa-3x"  name="candidate" value="{{
>> > candidate.id
>> > }}" />
>> >  
>> >  
>> >  
>> >  
>> >   > > class="portfolio-caption">
>> >  {{
>> > candidate.studentid.firstname }} {{ candidate.studentid.middlename }} {{
>> > candidate.studentid.lastname }} {{ candidate.studentid.suffix }}
>> >  > > class="text-muted">{{
>> > candidate.position }} - {{ candidate.party }}
>> >  
>> >  
>> >  
>> >  {% endif %}
>> >  {% endfor %}
>> >  
>> >  {% endif %}
>> >  {% endfor %}
>> >  {% endif %}
>> >  {% endfor %}
>> >  
>> >  
>> >  
>> >   
>> >  {% else %}
>> >  No Candidates Yet {% endif %}
>> >
>> > #models.py
>> >
>> > class Candidate(models.Model):
>> > studentid = models.OneToOneField(Student, on_delete=models.CASCADE)
>> > position = models.ForeignKey(Position, on_delete=models.CASCADE)
>> > party = models.ForeignKey(Party, on_delete=models.CASCADE)
>> > picture = models.ImageField()
>> > totalvotes = models.IntegerField(default=0)
>> > casvotes = models.IntegerField(default=0)
>> > citvotes = models.IntegerField(default=0)
>> > 

Re: How to login different user each on different pages using class based views

2017-02-14 Thread ludovic coues
I would add a get_redirect_url method on all user model, which give a
different url depending on the user category.
Then use a redirect url with a get_redirect_url method returning the
value of get_redirect_url from the user.

If you want to use url name instead of path, use django.urls.reverse

2017-02-14 12:00 GMT+01:00 JJEMBA KENNETH :
> Hello guys,
> I started using django a month back and I have been using class based views.
> they are pretty good. Then am wondering how i can use them to implement
> different categories of user where each is redirected to a different page.
> Can anyone please help me with that.
>
> --
> Jjemba Kenneth
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALHyo8_6KDbXOXBGDb6Gk1PbkRvsQ7L8H8XK3PK4b36W8_0mmQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEuG%2BTaOMC9iEOKPNoMFauW8rvwQ0X44PvUm%2B%3DeJJjg%3DS2i-5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Inconsistent types in PostgreSQL RangeFields

2017-02-14 Thread francois-xavier . thomas
Hello all,

I've been hitting a small annoyance when using the RangeField classes in 
the PostgreSQL contrib modules : while the value returned by psycopg is a 
psycopg.extras.Range type, the Django documentation explicitly mentions 
using tuples when creating and updating model instances.

This means that any method or property that has to process RangeFields must 
handle both tuples and Range types, which are incompatible.

For example, here is a very simple model :

class MyModel(models.Model):

range = DateTimeRangeField()

def has_started_1(self):
return self.range.lower() <= timezone.now()

def has_started_2(self):
return self.range[0] <= timezone.now()

In this naïve implementation, the `has_started_1` method will crash when 
used like this :

instance = MyModel.objects.create(range=(timezone.now(), timezone.now() 
+ timezone.timedelta(days=5))
instance.has_started_1()  # Crash
instance.has_started_2()  # True

...and the `has_started_2` method will crash with this :

instance = MyModel.objects.last()
instance.has_started_1()  # True
instance.has_started_2()  # Crash

How should I handle that better?

Thanks for your help!
François-Xavier

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/721d0534-35d4-4c8c-98af-913bcd39be56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django telebot ... !

2017-02-14 Thread Cassady Steel
I will UP this question :)

Amazon AWS. EC2 T2.micro Ubuntu

$ /usr/bin/python3

>>> import telebot
>>> token = "567891234:AAFcanBedGboDfLgVCak-Bqqc3i2NZfiGlg" (not actualy my 
token)
>>> bot = telebot.TeleBot(token)
>>> bot_id = bot.get_me()
>>> print(bot_id)
{'ok': False, 'error': 'Got unexpected response. (404) - 
{"ok":false,"error_code":404,"description":"Not Found"}'}

What can I do? :)
Thnx!

суббота, 21 января 2017 г., 0:15:04 UTC+3 пользователь ludovic coues 
написал:
>
> Please, can you send some of your code ? 
>
> 2017-01-20 18:58 GMT+01:00  : 
> > Hi ... 
> > I have a website that powerd by django . 
> > I can send message to my telegram channel with python client ( import 
> > telebot ) . 
> > But on website(django base) can't send message to channel and recive 
> blow 
> > error : 
> > 
> > {'error': 'Got unexpected response. (404) - 
> > {"ok":false,"error_code":404,"description":"Not Found"}', 'ok': False} 
> > 
> > why ? 
> > 
> > -- 
> > 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...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/dfa13bbb-391c-4a95-9a36-3836de62b456%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
>
> Cordialement, Coues Ludovic 
> +336 148 743 42 
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/798db85a-3bc3-44a4-88e8-db05b992564b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Admin keeps redirecting to login page repeatedly

2017-02-14 Thread Abdul Wahid
Yes, I removed that middleware and its working fine now. I would always
keep an eye these third party tools before blaming to django core.
Thanks for the advice.

Regards,
Abdul Wahid

On Tue, Feb 14, 2017 at 3:59 PM, Tim Graham  wrote:

> No idea but it seems like you should update your requirements per that
> project's readme: "Please note that django-zappa has been superceded by
> Zappa , which includes all of the
> django-zappa features and more!"
>
> Even the latest version of django-zappa doesn't have a middleware anymore.
> https://github.com/Miserlou/django-zappa/commit/
> 424143cdfe4057184e22eab5f6134b01b8685728
>
>
> On Monday, February 13, 2017 at 10:34:29 PM UTC-5, Abdul Wahid wrote:
>>
>> Hey Tim,
>>
>> Thanks for the hint, You are right the culprit was the *"*
>> django_zappa.middleware.ZappaMiddleware*"   *Its working fine without
>> this middleware but I require this middleware (Django Zappa)
>>  as for AWS lambda which
>> provides me serverless hosting.
>>
>> Please let me know if you know something about this middleware.
>>
>> Thanks,
>> Abdul Wahid
>>
>> On Tuesday, 14 February 2017 03:57:16 UTC+5:30, Tim Graham wrote:
>>>
>>> Can you create a minimal project that reproduces the problem? It seems
>>> like something in the request/response cycle (middleware maybe?) is
>>> effectively logging you out on each request.
>>>
>>> On Monday, February 13, 2017 at 5:07:09 PM UTC-5, Abdul Wahid wrote:

 Hi Everyone,

 Since last two nights, I am struggling a lot to resolve the issue as my
 Django admin section keeps redirecting to login page repeatedly.
 I had tried every corner solution to resolve the issue, but failed to
 resolve it.

 Finally I am writing here in some hope that someone who already had the
 similar issue would help me to resolve it.

 So I am using Django 1.9.4 and when I logged into admin section then
 its seems to be fine but when I reload the page or click on some button
 then it redirect me to login page, As per my investigation I found that I
 am getting 302 for *"admin/jsi18n"* see the below screenshot..


 

 Below is the screenshot after reloading the above mentioned page..


 



 I would really appreciate the help to resolve the issue and I need to
 move for production asap.


 Thanks,

 Abdul Wahid

 --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/F9XCiLDbkbY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/4c62e75b-0d5e-4327-9d93-d3d79dcad3c9%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BikFNqk6NrOfHfYyNFbxge5CcndZPu2JW94os3oybfFVSTEwQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Saving Data in Multiple Selected Checkbox for Voting System

2017-02-14 Thread Genaro Lubong
so I need to provide it? I am using def views for the template
On Feb 10, 2017 7:14 PM, "ludovic coues"  wrote:

> You didn't provide the view making use of that template
>
> 2017-02-10 10:49 GMT+01:00 Genaro Lubong :
> > please help me guys
> >
> >
> > On Feb 8, 2017 12:33 AM, "Genaro Lubong"  wrote:
> >
> > Hello, newbie here, I am currently making our capstone project as a
> > requirement to our course subject, and it is a major subject, while I
> was in
> > the part of retreiving the selected candidates, I was not about to
> iterate
> > the vote for those selected on the upper part, just the last selected
> > item/object/candidate, and since it is the major objective of our
> project,
> > and I am stucked with it and our team will be screwed if I didn't
> finished
> > it As Soon As Possible, here are my codes:
> >
> >
> > #views.py
> >
> > def vote(request):
> >  selected_candidate =
> > Candidate.objects.get(pk=request.POST.get('candidate'))
> >  selected_candidate.totalvotes += 1
> >   selected_candidate.save()
> >   return redirect('vs:index')
> >
> > #voting.html
> >
> > {% if all_candidates %}
> >  
> >  {% csrf_token %}
> >  {% for organization in all_organizations %}
> >  {% if all_positions %}
> >  {{ organization.organization }}
> >  {% for position in all_positions %}
> >  {% if organization == position.organization %}
> >  {{ position.position }}
> >  
> >  {% for candidate in all_candidates %}
> >  {% if position == candidate.position %}
> >  
> >  
> >   > data-toggle="modal">
> >   > class="portfolio-hover">
> >   > class="portfolio-hover-content">
> >   > type="checkbox" id="candidate{{ forloop.counter }}" class="candidate{{
> > position.id }} fa fa-check fa-3x"  name="candidate" value="{{
> candidate.id
> > }}" />
> >  
> >  
> >  
> >  
> >> class="portfolio-caption">
> >  {{
> > candidate.studentid.firstname }} {{ candidate.studentid.middlename }} {{
> > candidate.studentid.lastname }} {{ candidate.studentid.suffix }}
> >  {{
> > candidate.position }} - {{ candidate.party }}
> >  
> >  
> >  
> >  {% endif %}
> >  {% endfor %}
> >  
> >  {% endif %}
> >  {% endfor %}
> >  {% endif %}
> >  {% endfor %}
> >  
> >  
> >  
> >   
> >  {% else %}
> >  No Candidates Yet {% endif %}
> >
> > #models.py
> >
> > class Candidate(models.Model):
> > studentid = models.OneToOneField(Student, on_delete=models.CASCADE)
> > position = models.ForeignKey(Position, on_delete=models.CASCADE)
> > party = models.ForeignKey(Party, on_delete=models.CASCADE)
> > picture = models.ImageField()
> > totalvotes = models.IntegerField(default=0)
> > casvotes = models.IntegerField(default=0)
> > citvotes = models.IntegerField(default=0)
> > coevotes = models.IntegerField(default=0)
> > ctevotes = models.IntegerField(default=0)
> >
> >
> > I hope, you can help me guys, thank you so much 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 post to this group, send email to django-users@googlegroups.com.
> > Visit this group at https://groups.google.com/group/django-users.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/django-users/CACY%
> 3DutG8KLSZLYdpHpijg1QcY%3Dd0XP1DYoy8f-i_iNZwPPfi9g%40mail.gmail.com.
> >
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
>
> Cordialement, Coues Ludovic
> +336 148 743 42
>
> --
> 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 post to this 

How to login different user each on different pages using class based views

2017-02-14 Thread JJEMBA KENNETH
Hello guys,
I started using django a month back and I have been using class based
views. they are pretty good. Then am wondering how i can use them to
implement different categories of user where each is redirected to a
different page.
Can anyone please help me with that.

-- 
Jjemba Kenneth

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALHyo8_6KDbXOXBGDb6Gk1PbkRvsQ7L8H8XK3PK4b36W8_0mmQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Admin keeps redirecting to login page repeatedly

2017-02-14 Thread Tim Graham
No idea but it seems like you should update your requirements per that 
project's readme: "Please note that django-zappa has been superceded by 
Zappa , which includes all of the 
django-zappa features and more!"

Even the latest version of django-zappa doesn't have a middleware anymore.
https://github.com/Miserlou/django-zappa/commit/424143cdfe4057184e22eab5f6134b01b8685728

On Monday, February 13, 2017 at 10:34:29 PM UTC-5, Abdul Wahid wrote:
>
> Hey Tim,
>
> Thanks for the hint, You are right the culprit was the *"*
> django_zappa.middleware.ZappaMiddleware*"   *Its working fine without 
> this middleware but I require this middleware (Django Zappa) 
>  as for AWS lambda which 
> provides me serverless hosting. 
>
> Please let me know if you know something about this middleware.
>
> Thanks,
> Abdul Wahid
>
> On Tuesday, 14 February 2017 03:57:16 UTC+5:30, Tim Graham wrote:
>>
>> Can you create a minimal project that reproduces the problem? It seems 
>> like something in the request/response cycle (middleware maybe?) is 
>> effectively logging you out on each request.
>>
>> On Monday, February 13, 2017 at 5:07:09 PM UTC-5, Abdul Wahid wrote:
>>>
>>> Hi Everyone,
>>>
>>> Since last two nights, I am struggling a lot to resolve the issue as my 
>>> Django admin section keeps redirecting to login page repeatedly.
>>> I had tried every corner solution to resolve the issue, but failed to 
>>> resolve it. 
>>>
>>> Finally I am writing here in some hope that someone who already had the 
>>> similar issue would help me to resolve it.
>>>
>>> So I am using Django 1.9.4 and when I logged into admin section then its 
>>> seems to be fine but when I reload the page or click on some button then it 
>>> redirect me to login page, As per my investigation I found that I am 
>>> getting 302 for *"admin/jsi18n"* see the below screenshot..
>>>
>>>
>>> 
>>>
>>> Below is the screenshot after reloading the above mentioned page..
>>>
>>>
>>> 
>>>
>>>
>>>
>>> I would really appreciate the help to resolve the issue and I need to 
>>> move for production asap.
>>>
>>>
>>> Thanks,
>>>
>>> Abdul Wahid 
>>>
>>>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4c62e75b-0d5e-4327-9d93-d3d79dcad3c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.