djangoproject.com tutorial part 3

2014-10-20 Thread Tri Vo
So I am following the tutorial in this site, and copy and the first three 
codes into my project (polls/views.py, polls/urls.py, and mysite/urls/py)
https://docs.djangoproject.com/en/1.7/intro/tutorial03/

polls/views.py

from django.http import HttpResponse

def index(request):
return HttpResponse("Hello, world. You're at the polls index.")


polls/urls.py

from django.conf.urls import patterns, url
from polls import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),)

The next step is to point the root URLconf at the polls.urls module. In 
mysite/urls.pyinsert an include() 
, 
leaving you with:
mysite/urls.py

from django.conf.urls import patterns, include, urlfrom django.contrib import 
admin
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),)


When I launch my site, nothing changes. I do not see the "hello, world..." 
message at all. What did I do wrong?

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3b37469c-3fcb-48b5-81d9-a75190c1c432%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django builds incorrect sql-query

2014-10-20 Thread Алексей Широков
Hi,
I have 2 models:


@python_2_unicode_compatible
class Document(models.Model):
uuid = models.CharField(max_length=32, editable=False, unique=True)
contractor = models.ForeignKey(Contractor)
stagcy = models.ForeignKey(StateAgency)
type = models.CharField(max_length=25)
year = models.PositiveSmallIntegerField()
period = models.ForeignKey(Period, null=True, blank=True, 
related_name='+')
created = models.DateTimeField(auto_now_add=True)

class Meta:
unique_together = (
('contractor', 'stagcy', 'type', 'year', 'period'),
)
ordering = ('-created',)

def __str__(self):
return self.uuid


@python_2_unicode_compatible
class Sending(models.Model):
FLAGS = (
'F_CREATED',
'F_QUEUED',
'F_PREPARED',
'F_EXPORTED',
'F_SENT',
'F_CONFIRMED',
'F_COMPLETED',
'F_DELETED',
)

document = models.ForeignKey(Document, related_name='sendings')
uuid = models.CharField(max_length=32, editable=False, unique=True)
korr = models.PositiveSmallIntegerField(null=True, blank=True)
is_external = models.BooleanField(default=False)
user = models.ForeignKey(settings.AUTH_USER_MODEL)
state = bitfield.BitField(FLAGS, default=('F_CREATED',))
detail = jsonfield.JSONField(ensure_ascii=False, editable=False)
created = models.DateTimeField(auto_now_add=True)
queued = models.DateTimeField(null=True)
is_export_allowed = models.BooleanField(default=True)
exported = models.DateTimeField(null=True)
date_sent = models.DateTimeField(null=True)
completed = models.DateTimeField(null=True)
last_modified = models.DateTimeField(auto_now=True)
remark = models.CharField(max_length=1000, blank=True)
is_viewed = models.BooleanField(default=False)

class Meta:
ordering = ('-created',)

def __str__(self):
return self.uuid


Shell

>>> queryset = Document.objects.filter(sendings__user=1)
SELECT ...
FROM "document_document"
INNER JOIN "document_sending" ON ("document_document"."id" = 
"document_sending"."document_id")
WHERE "document_sending"."user_id" = 1
ORDER BY "document_document"."created" DESC 

>>>queryset.filter(sendings__state=0b001)
SELECT ...
FROM "document_document"
INNER JOIN "document_sending" ON ("document_document"."id" = 
"document_sending"."document_id")
INNER JOIN "document_sending" T4 ON ("document_document"."id" = 
T4."document_id")
WHERE ("document_sending"."user_id" = 1
   AND T4."state" = 1)
ORDER BY "document_document"."created" DESC 

Why...??? 
it is incorrect!!!

must be...

SELECT ...
FROM "document_document"
INNER JOIN "document_sending" ON ("document_document"."id" = 
"document_sending"."document_id")
WHERE ("document_sending"."user_id" = 1
   AND "document_sending"."state" = 1)
ORDER BY "document_document"."created" DESC 


How can I solve this problem?

Thanks
Alexi

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d7659d5e-8495-42e1-a037-056fc71309be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


djangoproject.com tutorial part 3 "Hello, World..." not showing up.

2014-10-20 Thread Tri Vo
I am using this site to learn Django, and at this link

https://docs.djangoproject.com/en/1.7/intro/tutorial03/

I created the polls/urls.py, polls/views.py, and mysite/urls.py files as 
followed in the site, but when I run the site, the site is running OK, but 
I do not see the "Hello, World..." message at all. Did I do something wrong?

If there's another post like this made by me, I'm posting second time 
because I do not see my first post in list.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6feb5d78-6d2d-4566-a30e-c2fd6c3de288%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django builds incorrect sql-query

2014-10-20 Thread Javier Guerra Giraldez
On Mon, Oct 20, 2014 at 1:53 AM, Алексей Широков  wrote:
> SELECT ...
> FROM "document_document"
> INNER JOIN "document_sending" ON ("document_document"."id" =
> "document_sending"."document_id")
> INNER JOIN "document_sending" T4 ON ("document_document"."id" =
> T4."document_id")
> WHERE ("document_sending"."user_id" = 1
>AND T4."state" = 1)
> ORDER BY "document_document"."created" DESC
>
> Why...???
> it is incorrect!!!
>
> must be...
>
> SELECT ...
> FROM "document_document"
> INNER JOIN "document_sending" ON ("document_document"."id" =
> "document_sending"."document_id")
> WHERE ("document_sending"."user_id" = 1
>AND "document_sending"."state" = 1)
> ORDER BY "document_document"."created" DESC


>From the docs [1]:
"To handle both of these situations, Django has a consistent way of
processing filter() and exclude() calls. Everything inside a single
filter() call is applied simultaneously to filter out items matching
all those requirements. Successive filter() calls further restrict the
set of objects, but for multi-valued relations, they apply to any
object linked to the primary model, not necessarily those objects that
were selected by an earlier filter() call."


in other words, your query is equivalent to:

Document.objects.filter(sendings__user=1).filter(sendings__state=0b001)

here, `sendings__user` and `sendings__state` appear on different
`filter()` calls, so each can refer to independent `Sending` objects.

try:

Document.objects.filter(sendings__user=1, sendings__state=0b001)

in this case, `sendings__user` and `sendings__state` appear on the
same `filter()` call, so they refer to `user` and `state` fields of
the same `Sending` object.


[1]: 
https://docs.djangoproject.com/en/1.7/topics/db/queries/#spanning-multi-valued-relationships

-- 
Javier

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFkDaoRsD0ZAT4dp2UKu58SH2RC_rYL_s-VW6xV_HRXJTvbyrg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django builds incorrect sql-query

2014-10-20 Thread Алексей Широков
Javier, I am unable combine 2 parameters in a single call filter(), because It 
is built on different levels of code.

Is there another solution???

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7ca806a0-8373-4333-8c42-2461eaffaedd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django builds incorrect sql-query

2014-10-20 Thread Javier Guerra Giraldez
On Mon, Oct 20, 2014 at 3:43 AM, Алексей Широков  wrote:
> Javier, I am unable combine 2 parameters in a single call filter(), because
> It is built on different levels of code.
>
> Is there another solution???


you can build up a dictionary and expand as parameters on a single
filter() call:

   params = {}
   params['sendings__user']=1
   ..
   params['sendings__state']=0b001
   ..
   qs = Document.objects.filter(**params)

i think you can also use a Q() object, but i'm not so sure about the
exact 'simultaneity' behavior.

-- 
Javier

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFkDaoTYGTkFNrM1Ncuw3OJQU5V_5pZ8zfAke0mB%3DUhZGvk_%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django builds incorrect sql-query

2014-10-20 Thread Алексей Широков
Thank you very much Javier!!! 

I've thought about it. I will try. 

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9645fd3d-8757-4f76-ac5a-a2539926fd04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: djangoproject.com tutorial part 3

2014-10-20 Thread Lee
When you say nothing changes, how are you calling the page? And what do you 
see in your browser - any error message or stack trace or is it just a 
blank page?

Also I assume the below were copied from the tutorial. Can you post the 
contents of the three files as you typed them in your code?

On Monday, 20 October 2014 04:31:57 UTC+1, Tri Vo wrote:
>
> So I am following the tutorial in this site, and copy and the first three 
> codes into my project (polls/views.py, polls/urls.py, and mysite/urls/py)
> https://docs.djangoproject.com/en/1.7/intro/tutorial03/
>
> polls/views.py
>
> from django.http import HttpResponse
>
> def index(request):
> return HttpResponse("Hello, world. You're at the polls index.")
>
>
> polls/urls.py
>
> from django.conf.urls import patterns, url
> from polls import views
> urlpatterns = patterns('',
> url(r'^$', views.index, name='index'),)
>
> The next step is to point the root URLconf at the polls.urls module. In 
> mysite/urls.pyinsert an include() 
> , 
> leaving you with:
> mysite/urls.py
>
> from django.conf.urls import patterns, include, urlfrom django.contrib import 
> admin
> urlpatterns = patterns('',
> url(r'^polls/', include('polls.urls')),
> url(r'^admin/', include(admin.site.urls)),)
>
>
> When I launch my site, nothing changes. I do not see the "hello, world..." 
> message at all. What did I do wrong?
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/33a5f0c4-2dba-4c3b-b1aa-d2f024f27c38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tango with Django - Populated Script

2014-10-20 Thread Andrew Crockett
Solution here: 
http://stackoverflow.com/questions/19699136/python-django-tangowithdjango-models-and-databases

On Wednesday, June 4, 2014 2:01:44 PM UTC+4, Srinivasulu Reddy wrote:
>
> Hello Folks,
>I am learning tangowithdjango book . In chapter 5 while dealing 
> the Populated Script i am getting this error . Please any one can help me 
> on this
>
> (mysite)seenu@acer:~/django_projects/seenu/tango_django$ python 
> populate_rango.py 
>
>  Starting Rango population script...
> Traceback (most recent call last):
>   File "populate_rango.py", line 60, in 
> populate()
>   File "populate_rango.py", line 4, in populate
> python_cat = add_cat('Python', views=128, likes=64)
>   File "populate_rango.py", line 52, in add_cat
> c = 
> Category.objects.get_or_create(name=name,views=views,likes=likes)[0]
>   File 
> "/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/manager.py",
>  
> line 134, in get_or_create
> return self.get_query_set().get_or_create(**kwargs)
>   File 
> "/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/query.py",
>  
> line 445, in get_or_create
> return self.get(**lookup), False
>   File 
> "/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/query.py",
>  
> line 361, in get
> num = len(clone)
>   File 
> "/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/query.py",
>  
> line 85, in __len__
> self._result_cache = list(self.iterator())
>   File 
> "/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/query.py",
>  
> line 291, in iterator
> for row in compiler.results_iter():
>   File 
> "/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
>  
> line 763, in results_iter
> for rows in self.execute_sql(MULTI):
>   File 
> "/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
>  
> line 818, in execute_sql
> cursor.execute(sql, params)
>   File 
> "/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/backends/util.py",
>  
> line 40, in execute
> return self.cursor.execute(sql, params)
>   File 
> "/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py",
>  
> line 114, in execute
> return self.cursor.execute(query, args)
>   File 
> "/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/MySQLdb/cursors.py",
>  
> line 205, in execute
> self.errorhandler(self, exc, value)
>   File 
> "/home/seenu/.virtualenvs/mysite/local/lib/python2.7/site-packages/MySQLdb/connections.py",
>  
> line 36, in defaulterrorhandler
> raise errorclass, errorvalue
> django.db.utils.DatabaseError: (1054, "Unknown column 
> 'rango_category.views' in 'field list'")
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9d461284-340b-4487-b392-61ef374e05db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: View didn't return an HttpResponse object

2014-10-20 Thread Dariusz Mysior
Now I try change this part of code in views.py

#request.user.set_password(form.cleaned_data['password2'])
#request.user.save()
#return render(request, 
'registration/change_password_success.html', {'user': request.user})

On 

from django.contrib.auth import logout,login,authenticate,*password_change*
.
.
.

password_change(request,'registration/change_password_success.html',
post_change_redirect=None,
password_change_form=FormularzPasswordChange, 
current_app=None, extra_context=None)

urls.py

This change

#url(r'^password_change/$', views.password_change_dom, 
name='change_password'),


On this

url(r'^password_change/$', 'django.contrib.auth.views.change_password'),

And I have message on first site :/


ImportError at / 
>
> cannot import name password_change
>
>  Request Method: GET  Request URL: http://darmys.pythonanywhere.com/  Django 
> Version: 1.6.5  Exception Type: ImportError  Exception Value: 
>
> cannot import name password_change
>
>  Exception Location: /home/darmys/dom/dom/views.py in , line 7




W dniu wtorek, 7 października 2014 20:37:49 UTC+2 użytkownik Dariusz Mysior 
napisał:
>
> I have form to change password like below, and when I try to display it I 
> have an bug:
>
> ValueError at /password_change/
>   
>
> The view dom.views.password_change_dom didn't return an HttpResponse object.
>
>
>   
>
> 
>   
>   
> 
> 
>   
>   
> 
>
> 
>   
>   
> 
>
> 
>
>   Request Method:GETRequest URL:
> http://darmys.pythonanywhere.com/password_change/Django 
> Version:1.6.5Exception 
> Type:ValueErrorException Value:
>
> The view dom.views.password_change_dom didn't return an HttpResponse object.
>
>
> My forms.py is:
> class FormularzPasswordChange(forms.Form):
> password1 = forms.CharField(label="Hasło:",widget=forms.PasswordInput
> ())
> password2 = forms.CharField(label="Powtórz hasło:",widget=forms.
> PasswordInput())
>
> def clean_password2(self):
> password1 = self.cleaned_data['password1']
> password2 = self.cleaned_data['password2']
> if password1 == password2:
> return password2
> else:
> raise forms.ValidationError("Hasła się różnią")
>
>
>
> urls.py
>
> url(r'^password_change/$', views.password_change_dom, name=
> 'change_password')
>
> change_password.html
>
> {% extends "base_site_dom.html" %}
>
> {% block title %} - zmiana hasła {% endblock %}
>
> {% block content %}
>
> 
> Zmiana hasła na nowe.
> Wpisz nowe hasło 2 razy.
> 
> 
> 
> {% csrf_token %}
> {{ form.as_p }}
>   value="Wartoci początkowe">
> 
> 
> 
> 
> {% endblock %}
> {% block footer %}
> 
> Strona głóna
> 
> {% 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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e0eb0d5e-151b-492c-b9d8-07096e2a5dc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Paginating 31 forms in to multiple pages( 16 forms per page)

2014-10-20 Thread wangolo joel
I have a  lot of form(31) am looking for a way to divide them into multiple 
pages but current I seem not to find any way of doing this.
All the other pagination  methods seem to favour those displaying data not 
those displaying forms.
Am using class based view(View)

DataInputProcessor(View):
 def get(self, request, dataset):
  #The source is way to much to post here.

 #after all forms in the pages have been filled post
 def post(self, request, dataset):
  #Allthis works for me but, how I can divide the forms in multiple 
pages not one.

Every thing seems to work for me inputing forms and posting all works, but 
the forms are too many And I
don't want the user to scroll the page until.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d4af230a-603a-4f9f-a33c-c2bdc9096019%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I use a django join to select customer_name for every id that is returned in a result from a summary table?

2014-10-20 Thread G Z
I've been looking into django joins, and I can see how I can select related 
fields with .select_related but I can't seem to get it to work how I want. 
I basically have summary tables that are linked to the customers table with 
customer_id FK's, I want to select the customer name from the customers 
field for every value returned for each of the summaries.

I included pseudo code to show what im trying to do.

sql would be = ''' select a.customer_name, b.vm_name, b.vm_cpu, 
b.vm_mem from customers a, vms b where a.customer_id = b.customer_id'''

how do I do that with django. That way when I loop through the returned 
values

for value in sql:
list.append(value.1, value.2, value.3)



that way I can associate and output the customer_name with each field.

Heres what I'm trying to do:

 compute_usages = ComputeUsages.objects.filter(customer_id = customer_id
).filter(load_date = datetime(year, day, selected_month)).select_related()
 for row in compute_usages:
if not 'Microsoft' in row.guest_os:
   compute_return_query_linux.append((row.customers.
customer_name, row.vm_name, row.vm_id, row.core_hours, row.ram_hours, row.
guest_os, row.provisioned_cores, row.provisioned_ram, row.datetime, row.
load_date)) 
else:
   compute_return_query_microsoft.append((row.customers.
customer_name, row.vm_name, row.vm_id, row.core_hours, row.ram_hours, row.
guest_os, row.provisioned_cores, row.provisioned_ram, row.datetime, row.
load_date))
   



obviously that doesn't work.

basically that one is for specific customers, but there is a case where 
company employees with admin rights can query the entire database for all 
customers and create a usage report so I need to associate customer_names 
with the query.




Any ideas on how to do this with django?


Models:

class Customers(models.Model):
customer_id = models.BigIntegerField(primary_key=True, editable=
False)
customer_name = models.CharField(max_length=100)
inactive = models.CharField(max_length=1)
datetime = models.DateTimeField()
class Meta:
managed = True
db_table = 'customers'

def __unicode__(self):  # Python 3: def __str__(self):
  return self.customer_name
   
def clean(self):
  if self.inactive != 'Y' and self.inactive != 'N':
 raise ValidationError('Please enter a Y or N')

class ComputeUsages(models.Model):
compute_usage_id = models.AutoField(primary_key=True, editable=False
)
customer = models.ForeignKey(Customers)
vm_name = models.CharField(max_length=4000)
vm_id = models.BigIntegerField()
core_hours = models.DecimalField(max_digits=15, decimal_places=2)
ram_hours = models.DecimalField(max_digits=15, decimal_places=2)
guest_os = models.CharField(max_length=100)
provisioned_cores = models.BigIntegerField()
provisioned_ram = models.BigIntegerField()
load_date = models.DateField()
datetime = models.DateTimeField()

class Meta:
managed = True
db_table = 'compute_usages'

def __unicode__(self):  # Python 3: def __str__(self):
  return self.vm_name


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/306a1cae-5901-4468-8834-a8d578a2929c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to "automatically " populate "last_updated_by" DB columns with the current user's id

2014-10-20 Thread Carl Meyer
Hi Ken,

On 10/18/2014 12:55 PM, Ken Winter wrote:
> OK, I've written and unit-tested the database components - see
> https://drive.google.com/file/d/0B-thboqjuKZTSjRHTXhqMlo3RlU/view?usp=sharing.
>  
> Now I could use a little advice on the Django part.
> 
> I believe that all that is needed is to have the app call the DB
> function set_session_user() while logging in the user, passing it the
> user id.  I guess my questions are:
> 
>  1. Where to put this call? - i.e. in what Django module and function?

I would not edit any module or function in Django. Editing Django
directly is just asking for trouble when you want to upgrade Django in
the future.

Fortunately, as in many cases, Django provides the extension hooks
necessary to do what you want without editing any Django code. There are
two techniques that come to mind:

1) You can write your own login view to replace (or wrap)
`django.contrib.auth.views.login`, which does the necessary database query.

2) You could write your own authentication backend (see
https://docs.djangoproject.com/en/1.7/topics/auth/customizing/),
probably just subclassing the default ModelBackend and adding your
database query in an overridden `authenticate()` method after
`ModelBackend.authenticate()` successfully authenticates the user.

Option 1 is simpler if your app has a typical login flow that always
goes through a single login view. Option 2 is lower-level and perhaps
more comprehensive if your app has multiple login flows/views.

>  2. How to make the call? - Is it just executing a SQL statement like
> "SELECT set_session_user()", or is there a better way?

I'm not sure what a "better way" would be; Django does not provide any
built-in API to call arbitrary database stored procedures, so you will
have to do this using raw SQL with `cursor.execute()`.

Carl

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/544550E7.7070408%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


Re: Debugging local Django app outside server root

2014-10-20 Thread Elliott
Update:

The django app and the django server are both using the same Python 
interpreter.

If I try to set a breakpoint in the app, the breakpoint does not exist 
warning actually is a local file but is in the remote_sources cache:

Connected to pydev debugger (build 135.1057)
pydev debugger: warning: trying to add breakpoint to file that does not 
exist: /Users/.../Library/Caches/PyCharm30/remote_sources/-1170959507/django
-app/example.py (will have no effect)

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/91775e9d-09db-4e57-9b44-4d6da984f844%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Customize admin page title (from tutorial)

2014-10-20 Thread Carl Meyer
Hi Pat,

On 10/18/2014 03:47 PM, Pat Claffey wrote:
> Hi,
> yes this is possible.  I have recently done this tutorial and succeeded
>  in customizing the title.
> In my opinion the instructions in this part of the tutorial are hard to
> understand.  Here is what I did:
> 
> 1.0 Navigate to the project directory mysite/mysite/ 
> 2.0 Create a new sub-directory called templates.  You should now have a
> directory mysite/mysite/templates/
> 3.0 Create a new sub-directory called admin in the above templates
> sub-directory.  You should now have a directory
> mysite/mysite/templates/admin/
> 4.0 Edit the settings file (mysite/settings.py) and add a TEMPLATE_DIRS
> setting:
> TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
> 5.0 Find the path of the django source files on your system.  
> To find this path open the python interpreter; import django and print
> the value of django.__path__ using the python command print(django.__path__)
> 6.0 On your file system navigate to the directory path obtained above
> from django.__path__ variable.  You should see a directory called
> contrib.  navigate to contrib/admin/templates/admin/
> You should see a source file called base_site.html
> 7.0 Copy the above source file base_site.html into the directory
> mysite/mysite/templates/admin/.  You should now have a file
> mysite/mysite/templates/admin/base_site.html
> 8.0 Edit the above file and replace {{ site_header|default:_('Django
> administration') }} (including the curly braces) with the new site name.
> If the desired new site name is "My Company Name" then you should see 
> My Company
> Name
> 9.0 Open the admin screen.  You may need to refresh this page.  You
> should now see that the label at the top of the page has changed.

I think these instructions are correct, except for the paths. Unless
you've modified the definition of the BASE_DIR setting in the default
Django project template, BASE_DIR will point to the outer workspace
"mysite" directory, not the inner Python package (mysite/mysite). So
you'd want to create `mysite/templates`, not `mysite/mysite/templates`,
to match a TEMPLATE_DIRS setting of `[os.path.join(BASE_DIR, 'templates')]`.

I'm not sure how to explain your success using the above steps. Perhaps
you have `'mysite'` in your INSTALLED_APPS, and thus your templates in
`mysite/mysite/templates` are being picked up by the app-dirs template
loader?

Carl

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5445529A.4020506%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


robots.txt 404 errors are not ignored, even though I put it in my settings file

2014-10-20 Thread Sabine Maennel
*Please can anybody help me with 404 errors?*

*I put this in my settingsfile: *
import re
IGNORABLE_404_URLS = (
re.compile(r'^/apple-touch-icon.*\.png$'),
re.compile(r'^/favicon\.ico$'),
re.compile(r'^/robots\.txt$'),
)

*but I still get 404 errors reported for robots.txt: What am I doing wrong 
here?*
Traceback (most recent call last):

  File 
"/srv/http/web0263/netteachers_live/lib/django/core/handlers/base.py", line 
150, in get_response
response = callback(request, **param_dict)

  File "/srv/http/web0263/netteachers_live/lib/django/utils/functional.py", 
line 15, in _curried
return _curried_func(*(args + moreargs), **dict(kwargs, **morekwargs))

  File "/srv/http/web0263/netteachers_live/lib/django/utils/decorators.py", 
line 99, in _wrapped_view
response = view_func(request, *args, **kwargs)

  File "/srv/http/web0263/netteachers_live/lib/django/views/defaults.py", 
line 30, in page_not_found
body = template.render(RequestContext(request, {'request_path': 
request.path}))

  File "/srv/http/web0263/netteachers_live/lib/django/template/context.py", 
line 169, in __init__
self.update(processor(request))

  File "/srv/http/web0263/netteachers_live/core/context_processors.py", 
line 9, in resolvermatch
match = resolve(request.path)

  File 
"/srv/http/web0263/netteachers_live/lib/django/core/urlresolvers.py", line 
480, in resolve
return get_resolver(urlconf).resolve(path)

  File 
"/srv/http/web0263/netteachers_live/lib/django/core/urlresolvers.py", line 
352, in resolve
raise Resolver404({'tried': tried, 'path': new_path})

Resolver404: {u'path': u'robots.txt', u'tried': [[ (admin:admin) ^admin/>], [ 
(None:application) ^bewerbung/>], [], 
[], [], 
[], [], [], [], [], [], [], [], [], 
[], []]}


,
POST:,
COOKIES:{},
META:{u'CSRF_COOKIE': u'PwJIAcfj8LQnL0yFygDyqrAvpvVqx5Lb',
 'GATEWAY_INTERFACE': 'CGI/1.1',
 'HTTP_ACCEPT': 'text/plain, text/html',
 'HTTP_ACCEPT_ENCODING': 'gzip,deflate',
 'HTTP_CONNECTION': 'close',
 'HTTP_FROM': 'googlebot(at)googlebot.com',
 'HTTP_HOST': 'netteachers.de',
 'HTTP_USER_AGENT': 'Mozilla/5.0 (compatible; Googlebot/2.1; +
http://www.google.com/bot.html)',
 'HTTP_X_FORWARDED_FOR': '66.249.65.33',
 'PATH_INFO': u'/robots.txt',
 'QUERY_STRING': '',
 'REMOTE_ADDR': '10.250.3.3',
 'REMOTE_PORT': '48208',
 'REQUEST_METHOD': 'GET',
 'REQUEST_URI': '/robots.txt',
 'SCRIPT_NAME': u'',
 'SERVER_NAME': 'netteachers.de',
 'SERVER_PORT': '80',
 'SERVER_PROTOCOL': 'HTTP/1.0',
 'wsgi.errors': ,
 'wsgi.file_wrapper': ,
 'wsgi.input': ,

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1062e95f-4c38-4737-83c4-9be30bfa92f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django.views.decorators.http.condition decorator

2014-10-20 Thread Anton Novosyolov
Opened, https://code.djangoproject.com/ticket/23695

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/322e182b-ad9c-47f6-89da-1b4724fa3559%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Getting started with django templatetags

2014-10-20 Thread Collin Anderson
Hello,

If you didn't say "can't modify models", I would for sure recommend custom 
methods on each model.

Otherwise, I think Thomas's suggestion is right.

Thanks,
Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/271c2feb-89a2-45fa-95e8-102867c6c3cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: View didn't return an HttpResponse object

2014-10-20 Thread Collin Anderson
Hello,

from django.contrib.auth import logout,login,authenticate,password_change
I think you want:
from django.contrib.auth import logout,login,authenticate
from django.contrib.auth.views import change_password

Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4b5511cb-5777-4090-961b-5705fe1661e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Paginating 31 forms in to multiple pages( 16 forms per page)

2014-10-20 Thread Collin Anderson
Hi,

Are you using model formsets? Would something like this might work?

page = Paginate(queryset, 16).page(request.GET.get('page') or 1)
formset = MyFormSet(queryset=page.object_list)

Collin


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4f3d8916-a388-4654-bc26-5a2c6e10eb59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: djangoproject.com tutorial part 3

2014-10-20 Thread Tri Vo
I am calling the page with "python manage.py runserver 0.0.0.0:8000" When I 
load up the page before adding the views and urls files, I see the polls 
and everything that I have set up with the codes from the previous pages of 
the tutorial. After adding the  views and urls files, the page looks the 
same like, even though the direction tells me that I should see the "Hello 
world" message that I put in the views file. I ran another directory with 
different way to put up the views like in this tutorial 
(http://www.djangobook.com/en/2.0/chapter03.html) and I got the views 
working by itself, but using the djangoproject tutorial, I do not see the 
message.

On Monday, October 20, 2014 3:48:33 AM UTC-7, Lee wrote:
>
> When you say nothing changes, how are you calling the page? And what do 
> you see in your browser - any error message or stack trace or is it just a 
> blank page?
>
> Also I assume the below were copied from the tutorial. Can you post the 
> contents of the three files as you typed them in your code?
>
> On Monday, 20 October 2014 04:31:57 UTC+1, Tri Vo wrote:
>>
>> So I am following the tutorial in this site, and copy and the first three 
>> codes into my project (polls/views.py, polls/urls.py, and mysite/urls/py)
>> https://docs.djangoproject.com/en/1.7/intro/tutorial03/
>>
>> polls/views.py
>>
>> from django.http import HttpResponse
>>
>> def index(request):
>> return HttpResponse("Hello, world. You're at the polls index.")
>>
>>
>> polls/urls.py
>>
>> from django.conf.urls import patterns, url
>> from polls import views
>> urlpatterns = patterns('',
>> url(r'^$', views.index, name='index'),)
>>
>> The next step is to point the root URLconf at the polls.urls module. In 
>> mysite/urls.pyinsert an include() 
>> , 
>> leaving you with:
>> mysite/urls.py
>>
>> from django.conf.urls import patterns, include, urlfrom django.contrib 
>> import admin
>> urlpatterns = patterns('',
>> url(r'^polls/', include('polls.urls')),
>> url(r'^admin/', include(admin.site.urls)),)
>>
>>
>> When I launch my site, nothing changes. I do not see the "hello, 
>> world..." message at all. What did I do wrong?
>>
>>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/70183f2b-a7d6-4280-a264-f6f5122d1120%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: robots.txt 404 errors are not ignored, even though I put it in my settings file

2014-10-20 Thread Collin Anderson
Hi Sabine,

IGNORABLE_404_URLS = (
re.compile(r'^/apple-touch-icon.*\.png$'),
re.compile(r'^/favicon\.ico$'),
re.compile(r'^/robots\.txt$'),
)
remove the slash at the beginning:
IGNORABLE_404_URLS = (
re.compile(r'^apple-touch-icon.*\.png$'),
re.compile(r'^favicon\.ico$'),
re.compile(r'^robots\.txt$'),
)

Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/52dc85db-db9a-4f5a-9d3d-501ab6e17191%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: OSQA multi language tutorial

2014-10-20 Thread Collin Anderson
Hello,

You're probably looking for this page.
https://docs.djangoproject.com/en/1.4/topics/i18n/translation/

Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cdd410ef-ea78-4e41-ac64-b7ff78f68806%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Specifying modelform meta field as get_user_model() in 1.7

2014-10-20 Thread Derek Leverenz
Hi,

I'm working on porting our codebase to django 1.7, and we use a custom user 
model. For that, we need to override the user creation and password reset 
forms. 
For the form's Meta class, we have

class Meta:
model = get_user_model()


where get_user_model is imported form django.contrib.auth. Because of 
changes made in 1.7, that can no longer be called at import time because 
the app registry is not ready. The troubleshooting section of the 1.7 
update notes suggests using settings.AUTH_USER_MODEL instead, however that 
doesn't work in this case, as far as I can tell. 

The only workaround I have come up with is simply to directly reference the 
custom user model. This will probably work fine for us, but it seems like 
it could cause problems for libraries, since they wont know what the custom 
model is. Is there a workaround for this? I'm not sure if I am just missing 
something.

thanks

--Derek Leverenz

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2e1a3233-eee9-4cc3-928e-ff77fcc50bc9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


dropdown_filter in django

2014-10-20 Thread Sachin Tiwari
Hi,

I want to make my custom filter into drop down filter,

class PersonIdFilter(SimpleListFilter):
title = _('Personid')

parameter_name ='personid'
contlist = list(PersonInfo.objects.all())

def lookups(self, request, model_admin):
lst = []
for id in self.contlist:
lst.append((id.personid,id.personid))
return tuple(lst)

def queryset(self, request, queryset):
if self.value() is None:
return queryset
return queryset.filter(personid__exact=self.value())

class PersonAdmin (admin.ModelAdmin):
   list_filter = (PersonIdFilter,)

The above filter is working for me, but I want to convert it into dropdown 
filter 

I tried with below approach 

Create a class in filters.py 

from django.contrib.admin.filters import AllValuesFieldListFilter

class DropdownFilter(AllValuesFieldListFilter):
template = 'admin/dropdown_filter.html'

Create a template in templates/admin/dropdown_filter.html
Copied from fiencms

{% load i18n %}
var go_from_select = function(opt) { 
window.location = window.location.pathname + opt };
{{ title }}

{% if choices|slice:"4:" %}


{% for choice in choices %}
{{ choice.display 
}}
{% endfor %}


{% else %}

{% for choice in choices %}

{{ choice.display 
}}
{% endfor %}

{% endif %}


And in my admin.py

from receivedata.filters import DropdownFilter
class PersonAdmin (admin.ModelAdmin):
   list_filter = (PersonIdFilter,DropdownFilter)

Error : type object 'PersonIdFilter' has no attribute 'split'

But it did not works for me,please suggest some other way

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bb9893cb-8927-4b33-886b-da4c4d9c8ce6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to query max count

2014-10-20 Thread dk
ok that max(the_max)  didn't work every time it provide a different result 
(looking into this) just updating the post in case someone was looking into 
this as a solution.

On Thursday, October 16, 2014 12:21:33 AM UTC-5, dk wrote:
>
> looks like it works like this
>
> the_max = Choice.objects.filter(date=date)
> print max(the_max)
>
>
>
>
>
> On Monday, October 13, 2014 6:14:28 PM UTC-5, dk wrote:
>
>> I need to learn how to use aggregation in django, I was thinking  on 
>> filter by date, 
>> and then loop the query and make a dictionary with the name, and += value 
>> and then use the python max function.
>>
>>
>> On Monday, October 13, 2014 3:12:39 AM UTC-5, JirkaV wrote:
>>
>>> Hi there, 
>>>
>>>   you could do it manually by counting occurrences or you could take a 
>>> look at aggregation functions here: 
>>> https://docs.djangoproject.com/en/1.7/topics/db/aggregation/
>>>
>>>   Do as it suits your use case.
>>>
>>>   HTH
>>>
>>> Jirka
>>>
>>> On 13 October 2014 06:30, dk  wrote:
>>>
 I am storing the information in the database like this.

 class Choice(models.Model):
 restaurant = models.ForeignKey(Restaurant)
 person = models.ForeignKey(Person)
 date = models.DateField("time published")
 time = models.TimeField("date published")


 that way I can get the person and the restaurant.   and will look like 
 in the attached pictures, now how can I query.
 the max repeated restaurant id, for today date.

 I want to know today what restaurant won.   =)  (I am trying to 
 even think on how to get this in a regular sql command)

 thanks guys.

 -- 
 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 http://groups.google.com/group/django-users.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/1628cbb6-f8ee-491b-a031-ad7aec787178%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a23eaefc-65e8-4763-8d0f-1d2c51136e46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Using ModelForm with ID associated with PostgreSQL Sequence

2014-10-20 Thread Néstor Boscán
Hi

I have an existing PostgreSQL database where all tables have sequences 
associated to their primary key and no, I can't change it.

When I create a ModelForm it generates "Required field" for the ID field 
because it doesn't have any data.

Any ideas how to manage this situation?

Regards,

Néstor

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/496384a5-0d3a-487c-819e-0c8cd952a897%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.