Re: How to serve a static file with django?

2015-12-23 Thread Jani Tiainen

Hi,

Also staticfiles and serving them is gone quire throughly in Django 
official tutorial part 6 



On 23.12.2015 06:57, Dan Bikle wrote:

*Hi List,*
*
I am new to django.

I read this:
https://docs.djangoproject.com/en/1.9/howto/static-files/

I did this:

cd ~
django-admin startproject mysite

I see this in
~/mysite/mysite/settings.py

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

So, I see staticfiles in there.

cd mysite
python manage.py startapp my_app
mkdir -p my_app/static/my_app
echo hello > my_app/static/my_app/hello.html
python manage.py runserver

Other terminal:

curl 127.0.0.1:8000/my_app/static/my_app/hello.html

gives:

Page not found (404)

So, I'm curious.

How to serve a static file with django?

I sense that
This URL is leaving out a step or maybe I read it wrong:
https://docs.djangoproject.com/en/1.9/howto/static-files/
??

I am running this django:

>>> import django
>>> print(django.get_version())
1.9
>>>
>>>
*
--
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/6ebacf12-c365-4a0d-bd23-c18926c9fff6%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/567A8E3E.1050702%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: New on Django and applications

2015-12-16 Thread Jani Tiainen

Hi,

First reply provided you to a starting point - official Django tutorial.

And considering that Django is web application framework you can build 
pretty much anything that you can imagine to work on web.


On 16.12.2015 12:49, Baptiste Guillaud wrote:

Hi !

I'm new on Django, I'm French and I study IT since 5 years.
In few years, it will a pleasure for me to contribute to Django but I 
must learn this framework in a first time


What type of application can we make with Django ? Do we use all 
library of python ?


Thanks for your response, see you !
--
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/9e936a9a-0ac8-45f1-a585-e10d588b17dc%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/56714656.2050608%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: get all current active connected users

2015-12-10 Thread Jani Tiainen

Hi,

That last login field only applies when user really logs in. (IOW you 
call login() function from django.contrib.auth). After that user is 
persisted to session so there is no need to authenticate per request.


Now if you have longer sessions than 24 hours user will stay logged in 
(I think default session TTL is 2 week after last modification). So that 
would still give troubles that users may have been active in last few 
seconds but not logged in for a few days.


On 09.12.2015 15:37, Jon Ribbens wrote:

On Wednesday, 9 December 2015 12:55:22 UTC, Jani Tiainen wrote:

This is really problematic domain since as you know, Django works
on HTTP request-response cycle. After cycle is finished there is
absolutely no way to know "who is logged on".

So first you have to determine factors that make up "currently
active user". Then you have to track that information somehow and
after that it's possible to gather a list of active/inactive users.


Users have a last_login field so you could easily say "users who have 
logged in in the last 24 hours" or whatever.

--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto: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/7c5f0620-c094-4667-b474-82a23f432fa1%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/7c5f0620-c094-4667-b474-82a23f432fa1%40googlegroups.com?utm_medium=email_source=footer>.

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


--

Jani Tiainen

--
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/566944D0.9020204%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: get all current active connected users

2015-12-09 Thread Jani Tiainen

Hi,

This is really problematic domain since as you know, Django works on 
HTTP request-response cycle. After cycle is finished there is absolutely 
no way to know "who is logged on".


So first you have to determine factors that make up "currently active 
user". Then you have to track that information somehow and after that 
it's possible to gather a list of active/inactive users.


On 09.12.2015 14:43, Fabio C. Barrionuevo da Luz wrote:

hello,
Django provide any API for get all users who are currently connected?

I need to run some scheduled tasks for users who are not connected and 
did not understand how I can get the users with active login via Session





--
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/5668248D.2070501%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Drop and replace SQL Table automatically when Model is migrated

2015-12-07 Thread Jani Tiainen
Django has built-in support for database migrations since version 1.7. 
In normal conditions you should be using at least version 1.8 (LTS, and 
lowest version supported now).


On 07.12.2015 03:48, Alexander Whatley wrote:

I will check with the people who made the IDE. Thanks for the input.

On Sunday, December 6, 2015 at 3:22:50 PM UTC-5, Alexander Whatley wrote:

This question may just be due to my inexperience with Django, but
whenever I modify one of my Model elements and change its
parameters, I have to close my IDE and manually use the command
prompt to drop the SQL Table corresponding to the Model, and then
migrate the new model, which is very annoying. Is there a built in
feature in Django that allows me to get around having to do this,
and if not, is there one in development? Thanks.

--
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/b39603db-175d-42ac-a607-229a961788c9%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/56656733.4050101%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How can I develop GeoDjango app that can uploaded shapefiles from a user(form) not from django admin

2015-11-26 Thread Jani Tiainen

Hi,

and welcome to wonderful world of GeoDjango. :)

https://docs.djangoproject.com/en/1.8/ref/contrib/gis/tutorial/#geographic-data

And specially:
https://docs.djangoproject.com/en/1.8/ref/contrib/gis/tutorial/#gdal-interface


On 26.11.2015 10:31, Mekonnen Legess wrote:
Hello everyone I am trying to develop some web GIS app using GeoDjango 
but I have no idea how to upload ESRI Shapefiles(.prj, .shx, .shp and 
.dbf)

--
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/c092f84e-951d-4cb3-9251-727e4209476f%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/5656E8DC.5020803%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using request object in settings.py for custom logging

2015-11-25 Thread Jani Tiainen
Well sites framework makes possible to do for example multitenancy 
inside database.


But apparently that is not your case. So why you like to log something 
per user? What's the real usecase here?


On 25.11.2015 11:45, Nikunj Badjatya wrote:

Thank you for your response.
Well our application is single site only. AFAIK, sites framework is 
useful when your django application serves multiple sites.

Can you throw some more light on what can be achieved using sites ?

I would like to evaluate all available options.

Thanks.


On Tuesday, November 24, 2015 at 4:54:36 PM UTC+5:30, Jani Tiainen wrote:

Hi,

Problem is that you quite certainly have different users and
several processess/threads which would lead logging configuration
per request.

Is there a reason you don't use something like sites framework to
differentiate clients?


On 24.11.2015 12:22, Nikunj Badjatya wrote:

Hello,

Currently for our application, all django logs are generated and
kept at '/var/log/django.log'
We want to have different log files for different clients. i.e.
/var/log/client-1/django.log
/var/log/client-2/django.log
/var/log/client-3/django.log



The request object has information about the logged in user (and
thus client). These inturn are stored in a mysql database.

How can django log file path be modified dynamically such that
when client-1 is using the application, his logs go into
'/var/log/client-1/django.log' and so on for other clients ?

Using Django 1.6.11 and Python 2.7.
'LOGGING' is defined in settings.py.

Thanks.

-- 
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
<http://groups.google.com/group/django-users>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/c7c7d27a-2804-4993-8bb9-dd9c3fb7eeab%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/c7c7d27a-2804-4993-8bb9-dd9c3fb7eeab%40googlegroups.com>.
For more options, visit https://groups.google.com/d/optout
<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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto: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/4e6070d9-b589-4001-b2c2-c9d3bbe8a4d3%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/4e6070d9-b589-4001-b2c2-c9d3bbe8a4d3%40googlegroups.com?utm_medium=email_source=footer>.

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/56558556.7010309%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using request object in settings.py for custom logging

2015-11-24 Thread Jani Tiainen

Hi,

Problem is that you quite certainly have different users and several 
processess/threads which would lead logging configuration per request.


Is there a reason you don't use something like sites framework to 
differentiate clients?



On 24.11.2015 12:22, Nikunj Badjatya wrote:

Hello,

Currently for our application, all django logs are generated and kept 
at '/var/log/django.log'

We want to have different log files for different clients. i.e.
/var/log/client-1/django.log
/var/log/client-2/django.log
/var/log/client-3/django.log



The request object has information about the logged in user (and thus 
client). These inturn are stored in a mysql database.


How can django log file path be modified dynamically such that when 
client-1 is using the application, his logs go into 
'/var/log/client-1/django.log' and so on for other clients ?


Using Django 1.6.11 and Python 2.7.
'LOGGING' is defined in settings.py.

Thanks.

--
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/c7c7d27a-2804-4993-8bb9-dd9c3fb7eeab%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/565448CB.9060203%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Requesting data from an API and rendering data on website

2015-11-18 Thread Jani Tiainen

Then I suggest that you do official tutorial from Django documentation.

It will give you a grasp what Django itself is and how it works. Django 
CMS is just built on top of Django so principles do apply there as well.


On 18.11.2015 13:14, nAncy sharma wrote:

Hi Avraham,

Yes that should work.
But since i am new to django cms , i don't know the files (ex: 
model.py ,view.py etc ) which all files need changes and where does 
the actual code of requesting to an API is to be written.





On Wednesday, November 18, 2015 at 4:26:16 PM UTC+5:30, Avraham Serour 
wrote:


Can you do it in plain python?


On Wed, Nov 18, 2015, 12:34 PM nAncy sharma <sharman...@gmail.com
> wrote:

Hi,


I am using Django Cms 3.1.3. I want to give a call (request )
to an API and display the result on my website.
Could anyone help me with this ? I am new to django cms !
-- 
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
<http://groups.google.com/group/django-users>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/85c04d98-8cbe-414b-808a-6ff1dede2442%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/85c04d98-8cbe-414b-808a-6ff1dede2442%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout
<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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto: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/7dc809a0-4f20-4cd6-99b8-d50e3e186285%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/7dc809a0-4f20-4cd6-99b8-d50e3e186285%40googlegroups.com?utm_medium=email_source=footer>.

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


--

Jani Tiainen

--
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/564C65F6.3070005%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Making a field readonly according to the user in admin.py

2015-11-18 Thread Jani Tiainen

Hi,

In general you shouldn't be even trying to do this in admin since it's 
not designed for this kind of functionality.


Admin is just a datacentric tool to view your data. It's never been 
meant to help implementing any businesslogic. And basically you only 
should let people in admin that you trust full 100%.


If you can't trust them (which is indicated by "readonly field" 
requirement) you should do custom view and templates for that. Generic 
class based views can greatly help you to achieve it, and most probably 
with really less effort than trying to do that in admin.



On 18.11.2015 12:15, Victor wrote:

Dear experts,

models.py

class Book(models.Model):
 title = models.CharField(max_length=100)
 author = models.CharField(max_length=100)
 quantity = models.IntegerField(db_column='quantitity',default=0)
 class Meta:
 db_table="book"

admin.py

class BookOption(admin.ModelAdmin):
 list_display = ('title', 'author', 'quantity')
 fields=(('title', 'author'), ('quantity'))
 order_by= ['title', ]

admin.site.register(Book,BookOption)


I'm trying to explain my problem with the simple example above.
Let's suppose that I have two staff users 'victor' and 'roby' and I want that 
the fields 'author and 'quantity' be readonly when user 'roby' is logged in and 
readwrite for user 'victor'
How can I achieve this result if possible with something of the following 
simple kind


class BookOption(admin.ModelAdmin):
 if (user is 'roby'):
readonly_fields=['quantity',]
 list_display = ('title', 'author', 'quantity')
 fields=(('title', 'author'), ('quantity'))
 order_by= ['title', ]
  
Thanks

Vittorio


--

Jani Tiainen

--
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/564C5123.1020501%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Timer for online examination

2015-11-17 Thread Jani Tiainen

Hello,

As I said, on client side doing timer requires javascript usage. But it 
doesn't remove need to actually make sure that no-one can manipulate 
duration of exam.


It's really trivial to have piece of javascript that would render plain 
javascript timer useless (like you could fill out form forever).


So to make sure cheating doesnt happen - at the moment exam is created 
exam end time should be recorderd on server side as well (in database 
for example). So even someone manages to hack the js (which is really 
simple) they can't overcome limitation from the server.


Like the rule #1 in web development says - "Never trust user input".

On 17.11.2015 09:47, Robin Lery wrote:

Hello,
I think you will  have to implement jquery/javascript to make the 
timer. After the countdown finishes js can post the form automatically.


Cheers.

On Tue, Nov 17, 2015 at 1:11 PM, Jani Tiainen <rede...@gmail.com 
<mailto:rede...@gmail.com>> wrote:


Hi,

If you're looking something magical there isn't anything. Just
declare expiracy timestamp and compare against it in code. It
should be rather trivial to do with JS down counter to UI for mode
concrete feedback to end user.

But keep final word of expiracy in Django code.


On 17.11.2015 08:28, Arindam sarkar wrote:

I am developing an online examination website. And having
difficulty implementing the timer .
Any one have done it or something related to countdown timer in
django ?

-- 
Regards,


Arindam

Contact no. 08732822385


-- 
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
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to
django-users@googlegroups.com <mailto: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/CAGnF%2BrAAv5DYpPWVxxOGV8%2BsE_w%3DKEhYSnBVArnRTggPuWXfyQ%40mail.gmail.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
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto: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/564ADA2D.501%40gmail.com

<https://groups.google.com/d/msgid/django-users/564ADA2D.501%40gmail.com?utm_medium=email_source=footer>.


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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto: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/CA%2B4-nGp_1wr-DeObEnrV9GvtpbvcY5hj%2B7R9%2Bqy3n81F6dFHtg%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CA%2B4-nGp_1wr-DeObEnrV9GvtpbvcY5hj%2B7R9%2Bqy3n81F6dFHtg%40mail.gmail.com?utm_medium=email_source=footer>.

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/564B0E10.50109%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Timer for online examination

2015-11-16 Thread Jani Tiainen

Hi,

If you're looking something magical there isn't anything. Just declare 
expiracy timestamp and compare against it in code. It should be rather 
trivial to do with JS down counter to UI for mode concrete feedback to 
end user.


But keep final word of expiracy in Django code.

On 17.11.2015 08:28, Arindam sarkar wrote:
I am developing an online examination website. And having difficulty 
implementing the timer .

Any one have done it or something related to countdown timer in django ?

--
Regards,

Arindam

Contact no. 08732822385


--
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/CAGnF%2BrAAv5DYpPWVxxOGV8%2BsE_w%3DKEhYSnBVArnRTggPuWXfyQ%40mail.gmail.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/564ADA2D.501%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Connecting to FirebirdSQL-Database as a second DB

2015-11-11 Thread Jani Tiainen
As I said, django-firebird is compatible with Django 1.6.x and older 
releases. So it won't work with Django 1.8.2


You do have three options:

1) Fix or ask someone to fix django-firebird to support Django 1.8
2) Use Firebird database without Django ORM directly.
3) Use Django 1.6.x (not recommended since it's unsupported)



On 11.11.2015 13:03, Djangaroo wrote:

Hi,

Thanks for the quick answer! No I'm not sure if it's compatible... I'm 
using Django 1.8.2 if that helps


I really don't know how I need to go about this. I can't find a way to 
connect my Database with the Django Project.


At the moment I'm trying to get this 
<https://github.com/cfingerh/django-firebird/tree/master>to work


On Wednesday, November 11, 2015 at 10:53:31 AM UTC+1, Jani Tiainen wrote:

Hi,

Are you sure that django-firebird is compatible with version of
Django you're using?

Docs seem to indicate that django-firebird supports only Django 1.6.x

On 11.11.2015 11:39, Djangaroo wrote:

Hello everybody,

I'm having trouble connecting a second Database to my Django Project.

I would like to read Data from the Firebirdsql database, to
display on my Website.

I have downloaded 'django-firebird' Link
<https://code.google.com/p/django-firebird/>

This is the setup I am using, wicht isn't working:

|
DATABASES ={
'default':{
'ENGINE':'django.db.backends.sqlite3',
'NAME':os.path.join(BASE_DIR,'db.sqlite3'),
},
'zef':{
'ENGINE':'firebird',
'NAME':os.path.join(BASE_DIR,'Blabla.FDB'),
'USER':'MyDBUser',
'PASSWORD':'Topsecret',
'HOST':'127.0.0.1',
'PORT':'3050',
}
}
|

and have also imported firebird and fdb:

|
importos,fdb,firebird
|

I still keep getting the following error message, when I try
running my Server:

django.core.exceptions.ImproperlyConfigured: 'firebird' isn't an
available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'base', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: cannot import name 'BaseDatabaseOperations'

I've been stuck here for a while and would really appreciate your
help.

-- 
You received this message because you are subscribed to the

Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to django-users...@googlegroups.com .
To post to this group, send email to django...@googlegroups.com
.
Visit this group at http://groups.google.com/group/django-users
<http://groups.google.com/group/django-users>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/62c7b456-08e3-4054-8b75-87cdf1c47451%40googlegroups.com

<https://groups.google.com/d/msgid/django-users/62c7b456-08e3-4054-8b75-87cdf1c47451%40googlegroups.com>.
For more options, visit https://groups.google.com/d/optout
<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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto: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/ea066a7d-a517-46e9-9e23-7faae86781a6%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/ea066a7d-a517-46e9-9e23-7faae86781a6%40googlegroups.com?utm_medium=email_source=footer>.

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/56432133.3050803%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Connecting to FirebirdSQL-Database as a second DB

2015-11-11 Thread Jani Tiainen

Hi,

Are you sure that django-firebird is compatible with version of Django 
you're using?


Docs seem to indicate that django-firebird supports only Django 1.6.x

On 11.11.2015 11:39, Djangaroo wrote:

Hello everybody,

I'm having trouble connecting a second Database to my Django Project.

I would like to read Data from the Firebirdsql database, to display on 
my Website.


I have downloaded 'django-firebird' Link 



This is the setup I am using, wicht isn't working:

|
DATABASES ={
'default':{
'ENGINE':'django.db.backends.sqlite3',
'NAME':os.path.join(BASE_DIR,'db.sqlite3'),
},
'zef':{
'ENGINE':'firebird',
'NAME':os.path.join(BASE_DIR,'Blabla.FDB'),
'USER':'MyDBUser',
'PASSWORD':'Topsecret',
'HOST':'127.0.0.1',
'PORT':'3050',
}
}
|

and have also imported firebird and fdb:

|
importos,fdb,firebird
|

I still keep getting the following error message, when I try running 
my Server:


django.core.exceptions.ImproperlyConfigured: 'firebird' isn't an 
available database backend.

Try using django.db.backends.XXX, where XXX is one of:
'base', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: cannot import name 'BaseDatabaseOperations'

I've been stuck here for a while and would really appreciate your help.

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+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/62c7b456-08e3-4054-8b75-87cdf1c47451%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/56430FE2.7090600%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: update_or_create() always creates (or recreates)

2015-11-06 Thread Jani Tiainen

Your problem lies on the way Django actually carries out create or update.

As name suggest, create or update does either one. But that's what you 
don't want - you want conditional update.


Only update if certain fields have been changed. Well this can be done 
few ways.


So you want to do 
"update_only_if_at_least_one_of_default_fields_changed_or_create"


Operation is simple, if object is not found, create new one using 
defaults if found, pull values as a dict, compare against
default values and if at least one differs do an update. Otherwise don't 
do anything.


So basically code would look something like this:

update_if_changed_or_create(**kwargs):
defaults = kwargs.pop('defaults', None)

qs = MyModel.objects.filter(**kwargs)

 if not qs:
obj = MyModel(**kwargs).save()
return obj, True  # Created object
else if len(qs) == 1:
obj = qs[0]
changed = False
for k, v in defaults:
 if getattr(obj, k) != v:
 changed = True
 setattr(obj, k, v)
if changed:
obj.save()
return obj, False  # Updated object
else:
# Multiple objects...

return obj, None  # No change.


On 06.11.2015 14:08, Yunti wrote:

Carsten ,

Thanks for your reply,

A note about the last statement: If a Supplier object has the same 
unique_id, and all
other fields (in `defaults`) are the same as well, logically there is 
no difference

between updating and not updating – the result is the same.

The entry in the database is the same - apart from the last_updated 
flag if it's not rewritten over the top of it.  This means I can check 
for new data often and be alerted when there is an actual update (i.e. 
a change to the data).  If it rewrites the data everytime it checks 
then I have no idea when data was actually updated.


Have you checked? How?
In your create_or_update_if_diff() you seem to try to re-invent 
update_or_create(), but

have you actually examined the results of the

 supplier, created = Supplier.objects.update_or_create(...)

call?

I checked by seeing that the last_updated field in the database was 
updated everytime.  (I suppose the issue could be with how that field 
gets reset to the next time it's run- I didn't eliminate that 
possibility.)


Yes I was worried that I might be recreating (a poor version) of 
update_or_create() but it didn't seem to have the option where it 
wouldn't write to the database if there was no change to the data.
Can it do this? And how would I verify when an item has been updated 
or created (or neither) - could I output to the console?


If it can how do I call it so it checks against all fields (unique_id 
and defaults) and updates using the defaults if it finds a difference 
(and creates if it doesn't find a unique_id)?


I'm still not sure if this is possible and how to call the function, 
particular how to pass in the remaining defaults to check against - 
**kwargs = defaults isn't right but not sure what it should be.


supplier, created = 
Supplier.objects.update_or_create(unique_id=product_detail['supplierId'], 
**kwargs=defaults, defaults={ 'name': product_detail['supplierName'], 
'entity_name_1': entity_name_1, 'entity_name_2': entity_name_1, 
'rating': product_detail['supplierRating']})

On Thursday, 5 November 2015 20:05:39 UTC, Carsten Fuchs wrote:

Hi Yunti, Am 05.11.2015 um 18:19 schrieb Yunti: > I have tried to
use the update_or_create() method assuming that it would either,
create > a new entry in the db if it found none or update an
existing one if it found one and had > differences to the defaults
passed in  - or wouldn't update if there was no difference. A note
about the last statement: If a Supplier object has the same
unique_id, and all other fields (in `defaults`) are the same as
well, logically there is no difference between updating and not
updating – the result is the same. >   However it just seemed to
recreate entries each time even if there were no changes. Have you
checked? How? In your create_or_update_if_diff() you seem to try
to re-invent update_or_create(), but have you actually examined
the results of the  supplier, created =
Supplier.objects.update_or_create(...) call? > I think the issue
was that I wanted to: > 1)  get an entry if all fields were the
same, update_or_create() updates an object with the given kwargs,
the match is not made against *all* fields (i.e. for the match the
fields in `defaults` are not accounted for). > 2) or create a new
entry if it didn't find an existing entry with the unique_id > 3)
or if there was an entry with the same unique_id, update that
entry with remaining > fields. update_or_create() should achieve
this. It's hard to tell more without additional information, but
https://docs.djangoproject.com/en/1.8/ref/models/querysets/#update-or-create


Re: can I write Django a client consuming RESTfull api from elsewhere

2015-11-05 Thread Jani Tiainen
Well your workflow would be following steps roughly:

1) End user requests URL from your Django site
2) Django router URL to a view
3) View code opens remote connection to RESTful service somewhere on the web
4) View code receive response from service
5) Data is processed
6) Data is rendered to end user

Now there is problem in step 3 and 4. That part may take long time
(minutes), what happens if service is down? Request will fail. Now what
happens at end user part? Browser will be waiting for response. Which in
turn connects to a frontend webserver which actually blocks either thread
or process. Now you hit second problem, what if you run for example 20
threads/processes in total. What happens when 21st request is coming in?
Well end user can't access your site at all because it's waiting for 20
older responses to come up.

That's why other people are suggesting that you don't request restful
service (unless you really can guarantee that it's fast) from view code but
do processing outside your web app. Like using background task to retrieve
data in timely manner and store it locally, or actually read that data
directly from the restful service without involving a django view.


If you could describe more of your use case, what data, what nature, why
you want to access it from a view we could give you a more specific help.


On Thu, Nov 5, 2015 at 3:31 AM, kk <krm...@gmail.com> wrote:

>
>
>
> On Wednesday 04 November 2015 10:43 PM, Avraham Serour wrote:
>
>> the question is why, why would you want to store a global connection for
>> a REST server?
>> keep in mind that you would be making HTTP requests, meaning even that
>> you had a global variable holding the connection it would just open and
>> close each tie you make a request.
>>
>
> No, I am not talking about the REST server.
> The REST server is a totally different service and I am just consuming it
> through Django views.
> So I have to use a client connection object such as Python request
> So I want to keep it as global, so that all views can access it from a
> single location, instead of creating a client request instance for every
> view on every call.
>
>
> Happy hacking.
> Krishnakant.
>
> --
> 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/563AB16E.9060604%40gmail.com
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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/CAHn91ocG3m3VaMKEE2ycamiFX4H6E%2BpiphXgegJyR63qneW12A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I relate two tables using field name instead of id?

2015-11-05 Thread Jani Tiainen
You need to set few additional attributes in your foreign key.

First you have to use db_column='', and to_field=''

db_column value would be column name in your table that holds foreign key.
I guess this would be 'name2' in your model that reflects table2

to_field would be reference in field in a model that reflects table1 db
column name1

So as a simplified example:

class MyModel1(models.Model):
name1 = model.CharField(max_length=123)

class Meta:
db_table = 'table1'

class MyModel2(models.Model):
name2 = model.ForeignKey('myapp.MyModel1', db_column='name2',
to_field='name1')

class Meta:
db_table = 'table1'

Hope that helps.


On Thu, Nov 5, 2015 at 6:12 PM, frocco <faro...@gmail.com> wrote:

> Thank you
>
> On Wednesday, November 4, 2015 at 11:19:40 AM UTC-5, frocco wrote:
>>
>> Hello,
>>
>> I have two existing tables
>> table1 has name1
>>
>> table2 has name2
>>
>> when I edit table2 in admin, I want a dropdownbox that shows values from
>> table1 using name1
>> both fields are character
>>
>> I cannot change the design, porting from msaccess
>>
>> thanks
>>
>> --
> 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/f42b087f-dffe-42df-994b-22e9028dd4c7%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/f42b087f-dffe-42df-994b-22e9028dd4c7%40googlegroups.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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/CAHn91ofvaaSWR-VPd9%3Dppc%3DOuM4Huo38Hf4zfb%2B-LmDcX0biYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Controlling access at table row level

2015-11-05 Thread Jani Tiainen

Django has foundation for object level (row level) perms:

https://docs.djangoproject.com/en/1.8/topics/auth/customizing/#handling-object-permissions

So basically you just check:

current_user.has_perm('permname', obj)

For a full list of methods you can check:
https://docs.djangoproject.com/en/1.8/ref/contrib/auth/#methods

On 05.11.2015 12:35, Steve West wrote:

Hi all

I'm implementing a Django project in which individual table rows are 
marked as either private or public. I need to be able to filter 
accesses to the tables in such a way that logged-in users can see 
everything, but other users only get visibility of the 'public' rows. 
My initial thoughts were that I could apply a check on whether the 
user is logged in in any of three places: at the model level, in views 
or in templates. It seemed to me that the most elegant and robust 
option would be to do so at the model level, by writing custom 
managers for my models. Within the custom managers, I could check if 
the user is logged in and filter all queries accordingly.


I did an initial implementation of the above approach, but quickly 
found problems. Whenever I span foreign key relationships in my views, 
the default model manager is invoked, so i have had to add in further 
tests for whether the user is logged in at the view level. I've also 
got some cases where foreign keys are spanned at the template level 
and have had to add further login tests there, too.


All-in-all, I don't think I am going about this in the right way!  In 
the Django documentation, it seems to be mostly expected that one will 
use authentication to control access to individual views or model 
operations, rather than controlling finer-grained access to individual 
rows, so I haven't found anything that really helps.


Can anyone please offer any advice or suggest what would be the best 
way of solving the problem or point my at any documentation that might 
help.


Many thanks

Steve
--
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/002471e1-8a64-4637-9d00-ae774924fd84%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/563B414A.70404%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to create a project in django in windows 7

2015-09-15 Thread Jani Tiainen

Hi,

I wrote a long time ago my setup I used when working in Windows. Since 
that I moved on to *nix since everything was just easier to get by.


Here's the link: 
https://djangonautlostinspace.wordpress.com/2012/04/16/django-and-windows/


On 15.09.2015 10:34, Nick Sarbicki wrote:


I am a fresher to django... can any one explain me how to install
django. and what all are the requirement needed. I tried by
searching google still am not able to do it. So any one please
help me.
Tank you.


Hi Santhosh,

Have you installed Python? (2.7 or 3.4 is best right now - 3.5 has 
just been released but there seems to be some bugs with the windows 
install).


If you have, and it is the latest version of 2.7 or 3.4, try opening 
up a command prompt window and typing in:


*pip install django*

That would normally install it for you.

If that doesn't work send any error messages you receive.

Here are the formal instructions to install Django:

https://docs.djangoproject.com/en/1.8/intro/install/

And here is the tutorial for getting started on a project:

https://docs.djangoproject.com/en/1.8/intro/tutorial01/

They are both pretty good so give them a read.

- Nick.



- Nick

On Tue, Sep 15, 2015 at 5:47 AM, Santhosh Acharya 
> wrote:


I am a fresher to django... can any one explain me how to install
django. and what all are the requirement needed. I tried by
searching google still am not able to do it. So any one please
help me.
Tank you.
-- 
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/4c5614d9-9c77-4338-acc6-1831f79abc23%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/CAGuvt93cSyDEd1DWRWCELYQb8BMds%3DSZiBpSotpXvCBNgBhNww%40mail.gmail.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/55F7D5B3.2010203%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: real time notification system

2015-09-14 Thread Jani Tiainen
There are several ways to do that but something like Twisted and 
Websockets or NodeJS and Websockets could do the trick. There also 
exists swampdragon project that is supposed to have all the goodies in 
easy to use format.



On 14.09.2015 14:20, shamila ali wrote:
How can implement real time notification system in django project.I 
need a notification system like facebook.

--
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/2be15881-6b6a-4346-b407-d731c7e81536%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/55F6B2D2.9040802%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: migration error "geo_db_type" when using postgres as second database for geodjango

2015-09-14 Thread Jani Tiainen

I guess you need to write a bit more:

https://docs.djangoproject.com/en/1.8/topics/db/multi-db/#allow_migrate

And sync_db is deprecated...

On 14.09.2015 13:07, Wenyao Xue wrote:
Following is my router for world app.  No router for other two apps, 
since default database is used

Settings:
DATABASE_ROUTERS = ['world.routers.GisRouter']

router.py in world app:
class GisRouter(object):
"""
A router to control all database operations on models in the
auth application.
"""
def db_for_read(self, model, **hints):
if model._meta.app_label == 'world':
return 'geodjango'
return None

def db_for_write(self, model, **hints):
"""
Attempts to write auth models go to auth_db.
"""
if model._meta.app_label == 'world':
return 'geodjango'
return None

def allow_relation(self, obj1, obj2, **hints):
"""
Allow relations if a model in the auth app is involved.
"""
if obj1._meta.app_label == 'world' or \
   obj2._meta.app_label == 'world':
   return True
return None

def allow_syncdb(self, db, model):
"""
Make sure the auth app only appears in the 'auth_db'
database.
"""
if db == 'geodjango':
return model._meta.app_label == 'world'
elif model._meta.app_label == 'world':
return False
return None

在 2015年9月14日星期一 UTC+8下午5:40:55,Jani Tiainen写道:



On 14.09.2015 11:58, Wenyao Xue wrote:

Hi,
I use mysql as default database and postgres for geodjango
related appliction.
my settings:
DATABASE_ROUTERS = ['world.routers.GisRouter',
'rest_shop.routers.ShopRouter',
'rest_client.routers.ClientRouter']

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'fddd',
'USER': **,
'PASSWORD': **,
'HOST': SERVER_HOST,
'PORT': '3306',
},
'geodjango': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'geo',
'USER': *,
'PASSWORD': ***,
'HOST': SERVER_HOST,
}
}

during migration, error raised:

Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm
4.5.4\helpers\pycharm\django_manage.py", line 41, in 
run_module(manage_file, None, '__main__', True)
  File "C:\Python27\lib\runpy.py", line 176, in run_module
fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
  File "D:\src\fddd_backend\manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File

"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\__init__.py",
line 338, in execute_from_command_line
utility.execute()
  File

"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\__init__.py",
line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File

"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\base.py",
line 393, in run_from_argv
self.execute(*args, **cmd_options)
  File

"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\base.py",
line 443, in execute
self.check()
  File

"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\base.py",
line 481, in check
include_deployment_checks=include_deployment_checks,
  File

"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\checks\registry.py",
line 72, in run_checks
new_errors = check(app_configs=app_configs)
  File

"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\checks\model_checks.py",
line 28, in check_all_models
errors.extend(model.check(**kwargs))
  File

"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\models\base.py",
line 1205, in check
errors.extend(cls._check_fields(**kwargs))
  File

"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\models\base.py",
line 1282, in _check_fields
errors.extend(field.check(**kwargs))
  File

"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\models\fields\__init__.py",
line 207, in check
errors.extend(self._check_backend_specific_checks(**kwargs))

Re: migration error "geo_db_type" when using postgres as second database for geodjango

2015-09-14 Thread Jani Tiainen



On 14.09.2015 11:58, Wenyao Xue wrote:

Hi,
I use mysql as default database and postgres for geodjango related 
appliction.

my settings:
DATABASE_ROUTERS = ['world.routers.GisRouter',
'rest_shop.routers.ShopRouter',
'rest_client.routers.ClientRouter']

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'fddd',
'USER': **,
'PASSWORD': **,
'HOST': SERVER_HOST,
'PORT': '3306',
},
'geodjango': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'geo',
'USER': *,
'PASSWORD': ***,
'HOST': SERVER_HOST,
}
}

during migration, error raised:

Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm 
4.5.4\helpers\pycharm\django_manage.py", line 41, in 

run_module(manage_file, None, '__main__', True)
  File "C:\Python27\lib\runpy.py", line 176, in run_module
fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
  File "D:\src\fddd_backend\manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\__init__.py", 
line 338, in execute_from_command_line

utility.execute()
  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\__init__.py", 
line 330, in execute

self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\base.py", 
line 393, in run_from_argv

self.execute(*args, **cmd_options)
  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\base.py", 
line 443, in execute

self.check()
  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\management\base.py", 
line 481, in check

include_deployment_checks=include_deployment_checks,
  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\checks\registry.py", 
line 72, in run_checks

new_errors = check(app_configs=app_configs)
  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\core\checks\model_checks.py", 
line 28, in check_all_models

errors.extend(model.check(**kwargs))
  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\models\base.py", 
line 1205, in check

errors.extend(cls._check_fields(**kwargs))
  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\models\base.py", 
line 1282, in _check_fields

errors.extend(field.check(**kwargs))
  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\models\fields\__init__.py", 
line 207, in check

errors.extend(self._check_backend_specific_checks(**kwargs))
  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\models\fields\__init__.py", 
line 306, in _check_backend_specific_checks

return connection.validation.check_field(self, **kwargs)


  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\db\backends\mysql\validation.py", 
line 18, in check_field

field_type = field.db_type(connection)
  File 
"C:\Python27\lib\site-packages\django-1.8.4-py2.7.egg\django\contrib\gis\db\models\fields.py", 
line 247, in db_type

return connection.ops.geo_db_type(self)
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'



Here it looks like Django is trying to validate something spatially 
related in you MySQL db and thus creating rather spurious error.


Do you have proper routing for migrations?



Is there something wrong with my settings?
--
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/3fa379ce-170f-48a3-911c-c8db168c6d53%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 

Re: What frontend-tools to use for a new CRM project? Shall I use Django OR switch to Meteor.js?

2015-09-10 Thread Jani Tiainen
I've been developing with Dojotoolkit and ExtJS. Both integrate with 
Django as well as any other JS framework.



On 10.09.2015 09:47, Mario Gudelj wrote:


+1 angular. Stack overflow is your friend and there's a lot of angular 
on it. You can do a lot with it with basic knowledge as well. And 
template syntax will make sense going to it from django


On 10 Sep 2015 3:53 pm, "Gergely Polonkai" > wrote:


Hello,

this is a bit off topic here, and highly opinion based, but here
are my two cents: I got along very well with both Bootstrap and
Angular, but never tried React before. However, a quick Google
search shows that React is barely supported yet (in terms of
available Django apps).

Best,
Gergely

On 10 Sep 2015 00:29, "ThomasTheDjangoFan"
> wrote:

Yeah, I definetly hate to write Javascript and I really do NOT
want to write server code in it.

*The parts where I really need a javascript framework in my
app are complex forms:
A page might consist of multiple forms bundled with formsets,
inline-forms and so on.*

*The question is:
*Which js-framework has the best form support for django? It
would be cool if I would just have to write server-side
model-variation and the client would adopt it.
Which js-framework has the best tutorial to get myself started?

*I checked out **www.djangopackages.com
 - it seems like I have the
following options:
*Angular.js: made by Google (6 django-pakets on
www.djangopackages.com )
JQuery.js: (4 django-pakets on www.djangopackages.com
)
Ember.js: (3 django-pakets on www.djangopackages.com
)
React.js: made by facebook (0 django-pakets on
www.djangopackages.com )
riot.js: (0 django-pakets on www.djangopackages.com
)

Any suggestions?

Kind regards
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/13e79d83-a4e5-4e6f-a372-47320791d9cd%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/CACczBUKWf6knewigf6ax6bheKje2jXUNs5uJ3%3DZ0KgiL2UxAXg%40mail.gmail.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/CAHqTbj%3Doas7sNhwK6YbV%3DHGL-j0ELkAwO94eCrUd00Esg_5BhQ%40mail.gmail.com 
.

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


--
You received this message because you are subscribed to the Google Groups "Django 

Re: django.db.utils.DatabaseError: ORA-12704: character set mismatch

2015-09-08 Thread Jani Tiainen

Hi,

Please provide following information:

Django version
Oracle database version
cx_Oracle version

If possible try to extract offending SQL.

On 09.09.2015 08:10, Mohsen Bande wrote:
i faced a strange issue, trying to store a list of items (of length 
~30) into database via |bulk_insert|, i get 
|django.db.utils.DatabaseError: ORA-12704: character set mismatch|but 
inserting items one by one via |save| is OK, even putting a few 
items(2~3) into |bulk_insert| sometimes works.

--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto: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/CAFdu22qPQGQgv8iByO51bm7TaQMayPJYzT69PMoJAN1S9K4reQ%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAFdu22qPQGQgv8iByO51bm7TaQMayPJYzT69PMoJAN1S9K4reQ%40mail.gmail.com?utm_medium=email_source=footer>.

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


--

Jani Tiainen

--
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/55EFC68A.1000201%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Oracle DB, some help needed

2015-09-08 Thread Jani Tiainen
Hi everyone,

I'm currently trying to maintain Oracle backends for Django and found
interesting issue that I would like Oracle users to run in their databases.

(I'm not sure can you run these in XE, you may try but I think these
require full Oracle)

Two SQL clauses that I would like you to run are located in my gist <
https://gist.github.com/jtiai/e3459777debf97458187>

Pay special attention to srsName value returned from queries, then please,
post your results and Oracle version your database is running.

If you don't want to post your results in public, private mail is
acceptable.

Thank you for your co-operation.

-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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/CAHn91of_R2%3DFeMvOceXA4jZPNEV5dpmsWvkAmN9zaO40xC5RkQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need help in Django Task

2015-08-18 Thread Jani Tiainen
Hi,

How much you pay for this work? :)

Sorry, you really have to do your homework...

On Mon, 17 Aug 2015 12:06:51 -0700 (PDT)
conticki <vandyk1...@gmail.com> wrote:

> Task to be done in Django 
> 
> Table structure:
> 
>- Movies
>   - id
>   - Title
>   - Description
>   - Featured image
>   - Movie length (in minutes)
>   - Movie release date
>
> Example:
> 
> 1 | Jurassic World | A movie about dinosaurs | 90 minutes | June 14 2015
> 2 | Kick | Salman Khan movie | 120 minutes | April 2014
> 
>- Category
>   - id
>   - Type
>   - Value
>
> 
> 1 | Language | English
> 2 | Genre | Action
> 3 | Language | Hindi
> 4 | Genre | Comedy
> 
> 
>- Relationship
>   - id
>   - Taxonomy id
>   - Movie id
>
> Example:
> 
> 1 | 1 | 1
> 2 | 1 | 2
> 3 | 2 | 3
> 4 | 2 | 4
> 
> 
> Create a list view of movies with pagination after 10 movies. 
> For pagination follow this approach. AJAX / Page Refresh  - your choice. 
> 
> 
>- Filter by language
>- Filter by Genre
>- Sort by Length
>- Sort by release date
> 
> Filter and sort need to work together. Filter and sort should continue to 
> work when I change page. For example refer 
> http://www.shortfilmwindow.com/movies/
> 
> Sort, filter and pagination need to be server side.
> 
> -- 
> 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/c31c4026-3efc-477e-b026-48e9e6364117%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
Jani Tiainen

-- 
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/20150818103804.55aa6f48%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Problems installing a Django package

2015-08-13 Thread Jani Tiainen
Throwing away virtualenv is actually best way to get problems (unless you're 
working with solutions like docker or vagrant).

Virtualenv makes easy to check that you really do have only certain packages, 
certain versions and they won't generate any sudden surprises.

On Thu, 13 Aug 2015 04:27:02 -0700 (PDT)
duriromp...@gmail.com wrote:

> I use no virtualenv, to throw away solutions in that direction.. (didn't 
> wanna to go hard first time).
> *pip* is only installed in 3.2, so that wasn't the problem. I've solved the 
> problem right now, but after an hour of trial and error, I think the only 
> think was to do *--upgrade wheel*. Is was just the problem of that package. 
> Maybe was broken when I installed it.
> 
> Thanks for the help!
> 
> 
> 
> El miércoles, 12 de agosto de 2015, 19:21:42 (UTC+2), girish ramnani 
> escribió:
> >
> >
> > Is wheel in latest version?
> > Also 
> >  
> > your wheel package is installed in 
> > wheel in /usr/local/lib/python3.2/dist-packages
> >
> > but the django-muro-humoristas
> > is being installed in 
> >
> > /home/rompepc/.local/lib/python3.2/site-packages
> >
> > So have you activated a virtualenv ? 
> >
> > Also i tried to installed a package using wheel it went into
> > shiboken in /home/girish/anaconda3/lib/python3.4/site-packages
> >
> > and location on wheel on my system is
> >
> > wheel in /home/girish/anaconda3/lib/python3.4/site-packages
> > so as you can see they both are same.
> >
> > you can try to install using
> > python -m pip install 
> >
> > to remove the ambiguity of different pips used to install.
> >
> >
> >
> > On Wednesday, August 12, 2015 at 1:32:39 AM UTC+5:30, durir...@gmail.com 
> > wrote:
> >>
> >> I did the tutorial for reusable apps for Django. All went well... but 
> >> then I get problems when installing the app.
> >> Processing ./django-muro_humoristas/dist/django-muro_humoristas-1.tar.gz
> >>   Requirement already satisfied (use --upgrade to upgrade): 
> >> django-muro-humoristas==1 from 
> >> file:///media/Comun/Programacion/Python/Django/Proyectos/muro_humoristas/django-muro_humoristas/dist/django-muro_humoristas-1.tar.gz
> >>  
> >> in /home/rompepc/.local/lib/python3.2/site-packages
> >> Building wheels for collected packages: django-muro-humoristas
> >>   Running setup.py bdist_wheel for django-muro-humoristas
> >>   Complete output from command /usr/bin/python3 -c "import 
> >> setuptools;__file__='/tmp/pip-ip3iaz-build/setup.py';exec(compile(open(__file__).read().replace('\r\n',
> >>  
> >> '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmp3885trpip-wheel-:
> >>   usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
> >>  or: -c --help [cmd1 cmd2 ...]
> >>  or: -c --help-commands
> >>  or: -c cmd --help
> >>   
> >>   error: invalid command 'bdist_wheel'
> >>   
> >>   
> >>   Failed building wheel for django-muro-humoristas
> >> Failed to build django-muro-humoristas
> >>
> >> Searching about the error, it looks like I just have to install *wheel*. 
> >> However, when I run the command *sudo pip install wheel* (*pip* is 
> >> installed under *Python3*):
> >> Requirement already satisfied (use --upgrade to upgrade): wheel in 
> >> /usr/local/lib/python3.2/dist-packages
> >>
> >> So, seeing that I can just going, I retry the package install and... get 
> >> the same error: "*invalid command 'bdist_wheel'"*. Anyone could tell me 
> >> what is going on? Is my first time doing a reusable app.
> >>
> >>
> 
> -- 
> 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/cff1f3fe-c0e0-4b0a-a135-ef87f70e0113%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
Jani Tiainen

-- 
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/20150813150605.6d0971a5%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Django vs ExtJS

2015-06-08 Thread Jani Tiainen
On Mon, 8 Jun 2015 10:12:17 -0700 (PDT)
Antonio Saponara <sapa...@gmail.com> wrote:

> ExtJS is a REST *client* wich uses  basic CRUD calls to obtain great 
> results with *few lines of code*!

That is true.
 
> It supports CRUD, pagination, sorting and filtering out of the box! Please 
> respect also the 2nd class citizen :-|

Sure, thing is that there is no support for HATEOAS, unless you code it your 
self so it makes working with anything more than simple data real painful. With 
ExtJS you have to know out of band information or like we did, wrote custom 
stuff to make things work better way. Begin fighting with ExtJS last 6 I've get 
used to take nothing as granted.

And what's painful is that ExtJS can't save relations (at least version 4.x). 
Unless you enhance saving functionality to do that.
 
> Django-rest-framework of course is  server-side so it is incomparable! It 
> does a lot of things exactly like many other frameworks. The real point is 
> that you, as a programmer appreciate django for features, reliability, and 
> many other aspects, but your customers needs to see other things like 
> available developers, competitors, references etc etc
> 
> I'd love to see django do the same thing i have done with my Zend proxy. 
> Manage a table's crud created in realtime with zero added code!

Well with Django admin you get all that. Plus nice way to view and edit your 
data. With a bit of additional definitions (coding iow) in admin parts you get 
even pretty good system to manage data, specially while you're developing.

> I mean, you configure the db connection, and every REST calls will manage 
> EVERY table in selected db via CRUD calls, automatically. 
> Without configuring table, keys, fields and so on.
> 
> This can be a great way to  scaffold a prototype really fast!
> 
> Once you are at an advanced stage, you can simply change the REST pointers 
> to a more advanced rest-server ;-)

Well DRF can do that, it requires a bit of code, but not hundreds of rows. See 
DRF generic views in the docs.

With a bit of coding you get all the goodies like nested (de)serialization 
(which ExtJS REST doesn't even support for writing OOTB)

But development speed was one of the big reasons why we chose Django (drf 
didn't existed though back then) and lately been adopting DRF.

And we, as our customers have been really happy with the choise. It's cheaper 
for our customers, and cheaper for us to develop.

One problem, as you noted as well, is to hire Python and Django pros.

-- 
Jani Tiainen

-- 
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/20150609085929.5087eb03%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Django vs ExtJS

2015-06-08 Thread Jani Tiainen
Hi,

I've been working with relatively large (GIS) apps that do use ExtJS and Django.

What comes to ExtJS and it's "REST" that is pure joke. It's not even close what 
REST should be. There is even long standing thread on ExtJS forums about having 
better support for REST but I guess it's totally 2nd class citizen in ExtJS 
world. But we chose ExtJS because it's components, specially grids and trees 
are pretty much best you can get for the money.

And as ExtJS is purely Javascript framework it doesn't have anything to do with 
actually Django, which is server side Web framework, written with Python.

What comes to Django it's development speed. You can evaluate and iterate 
development much faster in Django than in Java (at least in my experience). 
With development server just change something, go browser and refresh. With 
django-rest-framework (the big gun for REST apis in Django) you can even 
develop rest services without having special frontend for that - drf provides 
nice html API tool that makes developing (and even testing) faster - while 
you're building and testing your API you can have your frontend devs to do that.

And that's where Django and Python excels. Also Django has rather extensive set 
of tools that are crafted to work with web and database. ORM, Admin (which is 
valuable tool while developing), basic user system, authentication and 
authorization, permissions, form handling and data validation, and much more.



On Mon, 29 Dec 2014 06:55:57 -0800 (PST)
Joris Benschop <joris.bensc...@gmail.com> wrote:

> Hi List,
> 
> I;m a data maangement specialist in a rather large multinational. I'm 
> trying to push Django as a fast development framework for front-end 
> applications of our databases. Currently the company is focusing on Sencha 
> ExtJS and java solutions. Can you help me with pointers why Django is 
> better? The free-as-in-beer argument is not very convincing by itself. 
> 
> Thanks
> Joris
> 
> -- 
> 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/53e17853-9922-4f77-bf9a-4cea7d35ade3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
Jani Tiainen

-- 
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/20150608142228.5075be9b%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread Jani Tiainen
 on same network with my computer,then receive data
> >>> from
> >>> > another computer with the django(which is running on my computer(server
> >>> > side)).i am using built-in "runserver".
> >>>
> >>> so I suspect that you are doing something more that we missed. Perhaps
> >>> you could tell us why you want to do this?
> >>>
> >>> --
> >>> 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/20150507141332.GA27942%40d1stkfactory
> >>> .
> >>> 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/CACwh%3D0zjAYKjmyTJTWcucTyLM_iVaLokcgqREZpXgzp7e_GEGw%40mail.gmail.com
> >> <https://groups.google.com/d/msgid/django-users/CACwh%3D0zjAYKjmyTJTWcucTyLM_iVaLokcgqREZpXgzp7e_GEGw%40mail.gmail.com?utm_medium=email_source=footer>
> >> .
> >> 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/CAOs3Lp5N5RaBE7VRazeeA3gfc0Ccc5pRO7MNzCe-Z_rTr1Nsnw%40mail.gmail.com
> > <https://groups.google.com/d/msgid/django-users/CAOs3Lp5N5RaBE7VRazeeA3gfc0Ccc5pRO7MNzCe-Z_rTr1Nsnw%40mail.gmail.com?utm_medium=email_source=footer>
> > .
> >
> > 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/CACwh%3D0zKZrqHovzc%3DY0MAaBp21k9YvbAHqCBFdwH9knx8vr9LA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
Jani Tiainen

-- 
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/20150511163147.3d10504d%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Serialize QuerySet Q (not the result)

2015-04-22 Thread Jani Tiainen
Hi,

Straight from the docs:  

https://docs.djangoproject.com/en/1.8/ref/models/querysets/#pickling-querysets

"If you only want to pickle the necessary information to recreate the QuerySet 
from the database at a later time, pickle the query attribute of the QuerySet."

And in same place there even exists sample code how to restore pickled query.


On Wed, 22 Apr 2015 02:18:11 -0700 (PDT)
guettli <h...@tbz-pariv.de> wrote:

> Up to now only Q objects. If you know how to serialize aggregation / 
> annotations, this would be great :-)
> 
> Am Dienstag, 21. April 2015 14:35:52 UTC+2 schrieb Vijay Khemlani:
> >
> > Do you only need to serialize Q objects? No aggregation / annotations?
> >
> > On Tue, Apr 21, 2015 at 8:00 AM, guettli <h...@tbz-pariv.de > 
> > wrote:
> >
> >>
> >>
> >> Am Montag, 20. April 2015 17:12:21 UTC+2 schrieb Vijay Khemlani:
> >>>
> >>> Are the queries associated with a certain form? Or they are arbitrary 
> >>> queries?
> >>>
> >>>
> >> Good question. I would prefer a solution which is not associated with a 
> >> form. It is
> >> only associated with a model.
> >>
> >> Otherwise it would be easy. I just need to store the input values of the 
> >> form.
> >>
> >> I know that is very hard to make all filtering features available. But at 
> >> least the basic
> >> filtering should be serializable.
> >>
> >> Regards,
> >>   Thomas Güttler
> >>  
> >>
> >>> On Mon, Apr 20, 2015 at 10:01 AM, guettli <h...@tbz-pariv.de> wrote:
> >>>
> >>>> We want to store the QuerySet query (not the result) some how.
> >>>>
> >>>> Background: users should be able to save a complex query as "my 
> >>>> favorite query".
> >>>>
> >>>> Pickling querysets is possible, but version updates are not supported:
> >>>>
> >>>>   
> >>>> https://docs.djangoproject.com/en/1.8/ref/models/querysets/#pickling-querysets
> >>>>
> >>>> Simple queries (without OR) could be saved as dictionary.
> >>>>
> >>>> I have in mind some mini language which enables to store Q object 
> >>>> instances:
> >>>>
> >>>>  Q(foo='bar', blu='bla') | Q(foo='x', blu='y')
> >>>>
> >>>> And ordering 
> >>>>
> >>>> Before reinventing the wheel, I want to ask if someone has seen or done
> >>>> something like this before.
> >>>>
> >>>> I could not find an existing project. But maybe I used the wrong 
> >>>> keywords for
> >>>> my favorite search engine.
> >>>>
> >>>> Regards,
> >>>>   Thomas Güttler
> >>>>
> >>>> -- 
> >>>> 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/3f75c38e-d2c9-480c-9103-e4ea1bad8f88%40googlegroups.com
> >>>>  
> >>>> <https://groups.google.com/d/msgid/django-users/3f75c38e-d2c9-480c-9103-e4ea1bad8f88%40googlegroups.com?utm_medium=email_source=footer>
> >>>> .
> >>>> 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...@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/a8cc7fc6-4969-4d88-b39f-bd1511cfed54%40googlegroups.com
> >>  
> >> <https://groups.google.com/d/msgid/django-users/a8cc7fc6-4969-4d88-b39f-bd1511cfed54%40googlegroups.co

Re: view queryset object in admin view

2015-04-13 Thread Jani Tiainen
Hi, there are several flaws in your code.


On Mon, 13 Apr 2015 04:12:55 -0700 (PDT)
makayabou <makaya...@gmail.com> wrote:

> Hello,
> thanks for reply,
> of course attribute name was defined, I just ommited to past it!
> 
> Here's code:
> 
> [code]
> #In models.py:
> 
> 
> class PC(models.Model):
> def users(self):
> pc = self.user_set.all()
> for o in pc:
> return o.__unicode__

Here you return first (only first) __unicode__ method of "o" object.
Wild guess is that you want to do something like this:

def users(self):
return u', '.join([unicode(u) for u in self.user_set.all()])  ## Return 
comma separated list of users

> def __unicode__(self):
> return 'pc '+unicode(self.id)+' - '+self.os()

You declare unicode method, yet your return is a bytestring. You should put 
u-prefix before texts.

> 
> class User(models.Model):
> name=models.TextField()
> mypc = models.ForeignKey(PC)
> def __unicode__(self):
> return self.name   
> 
> 
> #In admin.py:
> 
> 
> class PcAdmin(admin.ModelAdmin):
> list_display = ('users','id')
> [/code]
> 
> Still have this weird print: 
> >
> 

That's correct output - first object and it's __unicode__ method - that's what 
you return in your code.

> instead of:
> Jean Dubois
> 
> thank you for help
> 
> Le lundi 13 avril 2015 07:57:00 UTC+2, Avraham Serour a écrit :
> >
> > Well, your class User doesn't have an attribute name you are using on the 
> > method __unicode__, you should define and set the attribute name with 
> > something like a textfield
> > On Apr 13, 2015 3:21 AM, "makayabou" <maka...@gmail.com > 
> > wrote:
> >
> >> Hello,
> >>
> >> Sorry for the previous send unattended...
> >>
> >> I have problems trying to print values of a QUerySet Object in Admin View.
> >>
> >> In admin view, I would like to get a clear list of results,
> >>> as defined in __unicode__ from class User.
> >>> Instead, I get:
> >>>
> >>> >
> >>>
> >>> I just need Jean Dubois..
> >>>
> >>> Here's the code:
> >>>
> >>> #In models.py:
> >>>
> >>>
> >>> class PC(models.Model):
> >>>  def users(self):
> >>>  pc = self.user_set.all()
> >>>  for o in pc:
> >>>  return o.__unicode__
> >>>  def __unicode__(self):
> >>>  return 'pc '+unicode(self.id)+' - '+self.os()
> >>>
> >>>
> >>>
> >>>
> >>> class User(models.Model):
> >>> mypc = models.ForeignKey(PC)
> >>> def __unicode__(self):
> >>> return self.name   
> >>>
> >>>
> >>> #In admin.py:
> >>>
> >>>
> >>> class PcAdmin(admin.ModelAdmin):
> >>> list_display = ('users','id')
> >>>
> >>>
> >> Thanks for your help. 
> >>
> >> -- 
> >> You received this message because you are subscribed to the Google Groups 
> >> "Django users" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an 
> >> email to django-users...@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/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com
> >>  
> >> <https://groups.google.com/d/msgid/django-users/61ec8171-77c5-4bba-9274-8f209422d15e%40googlegroups.com?utm_medium=email_source=footer>
> >> .
> >> 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/58ba4264-a9b1-4a7e-a86c-cc9d145deaab%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
Jani Tiainen

-- 
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/20150413142244.252d5d6d%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Seems like a geodjango bug with multiple databases

2015-02-20 Thread Jani Tiainen
On Wed, 18 Feb 2015 06:45:15 -0800 (PST)
Luan Nguyen <liha...@gmail.com> wrote:

> I'm using geodjango and multiple databases, and experiencing a quite weird 
> situation, I guess it's a kind of bug but not absolutely sure since I'm 
> pretty new to Django.
> 
> Here is how to reproduce the problem:
> - Set up another database besides default:
> DATABASES = {
> 'default': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> <http://django.contrib.gis.db.backends.postgis%27/>,
> 'NAME' : 'issue1',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> 'another': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> <http://django.contrib.gis.db.backends.postgis%27/>,
> 'NAME' : 'issue2',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> }
> 
> And two models:
> from django.db import models as default_models
> from django.contrib.gis.db import models
> # Create your models here.
> class Hotel(models.Model):
> hotel_name = models.CharField(max_length=255)
> objects = models.GeoManager()
> 
> class Room(models.Model):
> room_num = models.IntegerField()
> hotel = models.ForeignKey(Hotel, null=True, blank=True)

You don't have GeoManager on Room model? It's required to be default (first) 
manager if you do queries that even relate to geo-enabled model.

https://docs.djangoproject.com/en/1.7/ref/contrib/gis/model-api/#geomanager

And there reads: "It should also be noted that GeoManager is required even if 
the model does not have a geographic field itself, e.g., in the case of a 
ForeignKey relation to a model with a geographic field."
 
> Add data into issue2 database (leave issue1 blank), then go into shell:
> >>>h = Hotel.objects.using('another').all()[0]
> >>> h.id
> 9
> >>>h.room_set.all()[0].id <http://h.room_set.all%28%29[0].id/> #=> room id 
> 10 links to hotel id 9
> 10
> >>>r = Room.objects.using('another').get(pk=10)
> >>>r.hotel
> Traceback (most recent call last):
> File "", line 1, in 
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py
>  
> <http://applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py>",
>  
> line 572, in __get__
> rel_obj = qs.get()
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py
>  
> <http://applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py>",
>  
> line 357, in get
> self.model._meta.object_name)
> multi.models.DoesNotExist: Hotel matching query does not exist.
> 
> The thing is, if I create a hotel record on database issue1 with id of 9 
> then the last command works, so I guess it tried to look up in default 
> database. This doesn't have any problems if I use default manager for 
> Hotel, so I guess it's a bug?
> 
> -- 
> 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/daa291e8-bf87-422a-a8fc-b23038e94268%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
Jani Tiainen

-- 
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/20150220101236.1c721b6e%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: drop-in replacement for admin module foreign key relation UI

2015-02-16 Thread Jani Tiainen
On Mon, 16 Feb 2015 15:03:05 -0800 (PST)
Jani Kajala <kaj...@gmail.com> wrote:

> Hi all,
> 
> I have tons of objects referenced by ForeignKey in Django Admin module UI, 
> and I would like to replace it with something more optimal, e.g. auto-fill 
> input box or something.
> 
> My model looks something like this:
> 
> class SoapCall(models.Model):
> customer = models.ForeignKey(Customer, null=True, blank=True)
> created = models.DateTimeField(default=now)
> wsdl = models.CharField(max_length=255)
> func = models.CharField(max_length=63)
> request = models.TextField()
> response = models.TextField()
> 
> Now, this works great, but if I have 10 Customer objects it's not very 
> nice to generate one huge ... element for every page load.
> 
> There seems to be many possible plugins/implementations for this, but I was 
> just wondering if anyone would have up-to-date recommendations in this 
> mailing list. I'm on Python 3.4.2 and Django 1.7.4.

I would start with built-in implementation, a.k.a. rawid_id_fields 
<https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields>


-- 
Jani Tiainen

-- 
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/20150217091921.132995e2%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Tests and temp tables

2015-02-05 Thread Jani Tiainen
On Tue, 3 Feb 2015 19:38:31 -0500
Larry Martell <larry.mart...@gmail.com> wrote:

> I have a django app that uses a temp table. In the real world this is
> no issue, as each invocation of the app runs in its own MySQL session
> so there cannot be any conflict with the temp tables. But in my tests
> there are multiple requests sent, and apparently they are all in the
> same session, as on the second request I get an error because the temp
> table already exists. I tried logging out between requests, and I
> tried creating a new Client instance for each request, but I still got
> the error. Then I tried deleting the Client object, but I got Client
> object has no attribute __del__.
> 
> What I can do so that each request in a test has its own MySQL session?


Instead of Django standard TestCase (which internally wraps all in single 
transaction and makes transactions as a no-op), you should use 
TransactionalTestCase.

https://docs.djangoproject.com/en/1.7/topics/testing/tools/#transactiontestcase


-- 
Jani Tiainen

-- 
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/20150205142945.6569122d%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: django select extremely slow on large table

2015-01-23 Thread Jani Tiainen
On Fri, 23 Jan 2015 03:38:19 -0800 (PST)
Joris Benschop <joris.bensc...@gmail.com> wrote:

> And to keep replying to myself:
> 
> This one is slow:
> x=Marker.objects.raw("SELECT * from PROD_SCHEMA.MARKER WHERE MARKID= 
> %s",[u'TO1'])
> print x[0]
> 
> This one is fast:
> y=Marker.objects.raw("SELECT * from PROD_SCHEMA.MARKER WHERE MARKID= 'TO1'")
> print y[0]
> 
> If I copy the table and make the  MARKID field in NVARCHAR2(20), then it 
> uses the index properly on both counts
> 
> So... so do I make django use ascii? is there a field type?

You could try explicit cast to VARCHAR2, not sure does that help at all:

x=Marker.objects.raw("SELECT * from PROD_SCHEMA.MARKER WHERE MARKID=CAST(%s AS 
VARCHAR2)",[u'TO1'])


-- 
Jani Tiainen

-- 
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/20150123135923.25a181aa%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: django select extremely slow on large table

2015-01-23 Thread Jani Tiainen
On Fri, 23 Jan 2015 03:38:19 -0800 (PST)
Joris Benschop <joris.bensc...@gmail.com> wrote:

> And to keep replying to myself:
> 
> This one is slow:
> x=Marker.objects.raw("SELECT * from PROD_SCHEMA.MARKER WHERE MARKID= 
> %s",[u'TO1'])
> print x[0]
> 
> This one is fast:
> y=Marker.objects.raw("SELECT * from PROD_SCHEMA.MARKER WHERE MARKID= 'TO1'")
> print y[0]
> 
> If I copy the table and make the  MARKID field in NVARCHAR2(20), then it 
> uses the index properly on both counts
> 
> So... so do I make django use ascii? is there a field type?
> 
> -- 
> 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/50ce32f1-90ac-4290-a950-ed70c7e9692b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

It's pretty much impossible without writing custom backend or magical
monkey patching. In upcoming 1.8 or 1.9 is possible to write custom
translators that could help.

If I were you I most probably would resort with fast version of raw
query for now and just document that it's insecure and will be replaced
something better as soon as such a mechanism is available.

-- 
Jani Tiainen

-- 
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/20150123135514.2be10d36%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: django select extremely slow on large table

2015-01-23 Thread Jani Tiainen
On Fri, 23 Jan 2015 02:06:58 -0800 (PST)
Joris Benschop <joris.bensc...@gmail.com> wrote:

> Very interesting point.
> In the backend the MARKID column is of type VARCHAR2(20 BYTE).  This is not 
> something I can change. But it does seem that the bindvar method forces a 
> unicode lookup onto an ascii table.
> 
> Is there any way to make django get this field in ascii to test this theory?

Hi, I remember having lot of slowness in my 21M row table when I
discovered this issue: https://code.djangoproject.com/ticket/11017

Not sure if that is any help. But I remember that when oracle drops to
implicit data type conversions things tend to get sideways.


-- 
Jani Tiainen

-- 
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/20150123122349.2b57919c%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: django select extremely slow on large table

2015-01-22 Thread Jani Tiainen
Hi,

1.5b rows is rather big data.

Could you test what .values() or .values_list() produces in terms of speed.

also print qs might actually pull in all selected records in Python memory so 
it may take a while to constuct bunch of objects.


On Thu, 22 Jan 2015 07:32:36 -0800 (PST)
Joris Benschop  wrote:

> Dear List,
> 
> I'm trying to run a simple select on a very large Oracle table (1500 
> million records). 
> 
> I create a standard django model:
> --
> class Marker(models.Model):
> marker_id = SYSGUID16Field(primary_key=True)  # This field type is a 
> guess.
> markid = models.CharField(unique=True, max_length=20, blank=True)
> crop = models.ForeignKey("variantdb_admin.Crop", blank=True, null=True)
> insid = models.CharField(max_length=5, blank=True)
> insdate = models.DateTimeField(blank=True, null=True)
> 
> class Meta:
> managed = False
> db_table = "prod_schema"."marker"
> --
> 
> then simply run:
> >>> x = Marker.objects.filter(markid = 'TO11')
> >>> print x
> 
> in debugger, this basically creates the following simple query:
> DEBUG (44.120) QUERY = u'SELECT "PROD_SCHEMA"."MARKER"."MARKER_ID", 
> "PROD_SCHEMA"."MARKER"."MARKID", "PROD_SCHEMA"."MARKER"."CROP_ID", 
> "PROD_SCHEMA"."MARKER"."INSID", "PROD_SCHEMA"."MARKER"."INSDATE" FROM 
> "PROD_SCHEMA"."MARKER" WHERE "PROD_SCHEMA"."MARKER"."MARKID" = :arg0' - 
> PARAMS = (u'TO11',); args=('TO11',)
> 
> As you see, in Django this takes 44 seconds to run. 
> If I run this exact same query with cx_oracle directly the response time = 
> < 0.1sec.
> 
> For small tables the performance of django is quite good, so it almost 
> seems like django tries to do a count on the table before runnign the query 
> or something. Any suggestions on how I can make this lookup faster?
> 
> thanks
> joris
> 
> 
> 
> -- 
> 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/7db20206-9af7-491f-a0ed-b84f43cd4096%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/20150123082311.4729cd3d%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Django with ExtJs, any app ?

2015-01-22 Thread Jani Tiainen
Hi,

Easier on what sense? I've had great success with django-rest-framework and 
ExtJS as is for a long time, without need to have an app to do anything for me.

On Thu, 22 Jan 2015 13:17:09 -0200
Fellipe Henrique  wrote:

> Hello,
> 
> There's any app to make easier manipulate data using Django and ExtJ?
> 
> T.·.F.·.A.·. S+F
> *Fellipe Henrique P. Soares*
> 
> e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
> *Blog: http://fhbash.wordpress.com/ *
> *GitHub: https://github.com/fellipeh *
> *Twitter: @fh_bash*
> 
> -- 
> 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/CAF1jwZEzk6TbTpNWtyiwYYJHf4Q8YVTs5VUvUgmmciT%2BZnze-A%40mail.gmail.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/20150123081421.7850fb08%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Processing uploaded csv on the basis of user input

2015-01-15 Thread Jani Tiainen
Hi,

I do something similiar this way:


You could leverage Django (model)form to validate date and to normalize
it to proper data.

That way you would put design a contract between users that you state
which column names are matched to your internal data.

Then feed each row to (model)form if row is valid, you can save it, if
not you can log errors for showing them after import is done.

Another option is (what you're proposing) is to have such a dynamic
middle form to make mapping between columns frm csv and your model.
After that just map values from CSV to a dict, pass it to (model)form,
validate and save if valid.

As you see, Django (model)form is _very_ useful to validate user input
- even input is not directly from HTML form.

On Thu, 15 Jan 2015 18:54:13 -0800 (PST)
David Mutton <david.w.mut...@gmail.com> wrote:

> 
> 
> Please let me know if this is an inappropriate question. I feel it is
> a little broad.
> 
> I am fairly new to Django and coding an app for educational purposes.
> What I am trying to achieve is to allow users to upload a CSV and
> then populate a model by specifying that datatype that is in each
> column of the CSV. I’m fine with the first half (users can upload csv
> which are then processed into a PropertyQuery model but currently
> they would need to download a template CSV file and ensure they
> conform to it. I’d like them to be able to upload any CSV and then
> specify the column’s data.
> 
> I don’t need a step by step explanation on how to achieve this but
> after spending a fair chunk of time searching I could use a pointer.
> 
> I hope that my flowchart below explains it better.
> 
> Many thanks.
> 
> <https://lh5.googleusercontent.com/-tVJ3uUxlrEk/VLh9RViDypI/A5U/fv34Zq-Y4Qs/s1600/flowchart.png>
> 
> 
> -- 
> 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/c5acdad9-eb00-438a-bf37-faf7a66a82a5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 

Jani Tiainen

-- 
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/20150116085438.0f3b4fec%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Desired: Field behavior like AutoField + unique_with

2015-01-13 Thread Jani Tiainen
Because sequence number was running number per "tenant" (in my case it
was invoice type) that started from zero (0) at the beginning of the
every year.

You could use max+1 as well but you should be aware that there is a
slim chance that there is race condition and you may end up having two
entities with the same max number - that though would raise error when
trying to save into database.

By having explicitly pessimistic locking (select_for_update) for a row
with tenant + sequence value you can guarantee that no other request
can change the value while you're reading it.

To make that easier you can create custom manager that can retrieve
updated sequence values automagically, so your call would look like
something like:

Tenant.sequence.get_value(tenant, sequence)


On Tue, 13 Jan 2015 06:37:21 -0800 (PST)
Matt Cooper <vtbassm...@gmail.com> wrote:

> Thanks Jani, good to hear someone has gone down this road before.
> Since you did it in code, is there a reason you kept a sequence value
> on Tenant rather than using
> Widget.objects.aggregate(Max(Widget.sequence_value)) ? I ask because
> for my app, Widget is actually just one of several cases where I need
> this pattern. If I could keep all the book-keeping on the model with
> the constraint, that seems cleaner to me. But, of course, I'm not
> willing to pay a huge performance or corruption penalty just for
> vague ideological purity :)
> 
> Thanks again!
> ~matt
> 
> On Tuesday, January 13, 2015 at 5:07:21 AM UTC-8, Jani Tiainen wrote:
> >
> > I've done something similiar. 
> >
> > Only way to do that is that you need to upkeep that tenant
> > sequence_id manually, 
> >
> > So doing something like: 
> >
> > class Tenant(models.Model): 
> > name = models.CharField(max_length=50) 
> > sequence_value = models.IntegerField() 
> >
> > and in a code: 
> >
> > tenant = Tenant.object.get(id=tenant_id).select_for_update()  # 
> > Pessimistic locking 
> > tenant.sequence_value = tenant.sequence_value + 1 
> > tenant.save() 
> >
> > widget = Widget(owner=tenant,sequence_value=tenant.sequence_value) 
> > widget.save() 
> >
> > That should do the trick. Another option could be using table
> > triggers to automate 
> > that within a database table trigger(s). 
> >
> > On Mon, 12 Jan 2015 21:26:54 -0800 (PST) 
> > Matt Cooper <vtbas...@gmail.com > wrote: 
> >
> > > I'm building a multi-tenant application with a data model that 
> > simplifies 
> > > to: 
> > > 
> > > class Tenant(models.Model): 
> > > name = models.CharField(max_length=50) 
> > > 
> > > class Widget(models.Model): 
> > > owner = models.ForeignKey(Tenant) 
> > > sequence_id =  
> > > 
> > > 
> > > I want Widget.sequence_id to work like an AutoField (that is, 
> > automatically 
> > > give me something unique and generally incrementing by 1) but
> > > scoped to 
> > a 
> > > single Widget.owner. So for instance, when Tenant A creates 3
> > > widgets, 
> > they 
> > > would get sequence_ids 1, 2, and 3. Then Tenant B comes along and 
> > creates 2 
> > > widgets; those widgets get sequence_ids 1 and 2. The tenant/user
> > > gets no control over the number, but it's something she'll see in
> > > the UI. AutoNumber is out because from the perspective of a
> > > single tenant, they should have sequential widget IDs.
> > > GUIDs/UUIDs are out because it needs 
> > to 
> > > be human-readable. 
> > > 
> > > I looked through docs on AutoField and unique_together. I turned 
> > > StackOverflow upside down and only found this 
> > > <http://stackoverflow.com/questions/18072586/django-autofield-increment>, 
> >
> > > which isn't quite what I want. I didn't see anything on 
> > djangopackages.com 
> > > that would solve my problem, though I could have missed it. 
> > > 
> > > Basically, has anyone done something like this before and have a 
> > suggested 
> > > pattern? 
> > > 
> > > Thanks! 
> > > ~matt 
> > > 
> > > -- 
> > > 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

Re: Desired: Field behavior like AutoField + unique_with

2015-01-13 Thread Jani Tiainen
I've done something similiar.

Only way to do that is that you need to upkeep that tenant sequence_id manually,

So doing something like:

class Tenant(models.Model):
name = models.CharField(max_length=50)
sequence_value = models.IntegerField()

and in a code:

tenant = Tenant.object.get(id=tenant_id).select_for_update()  # Pessimistic 
locking
tenant.sequence_value = tenant.sequence_value + 1
tenant.save()

widget = Widget(owner=tenant,sequence_value=tenant.sequence_value)
widget.save()

That should do the trick. Another option could be using table triggers to 
automate
that within a database table trigger(s).

On Mon, 12 Jan 2015 21:26:54 -0800 (PST)
Matt Cooper  wrote:

> I'm building a multi-tenant application with a data model that simplifies 
> to:
> 
> class Tenant(models.Model):
> name = models.CharField(max_length=50)
> 
> class Widget(models.Model):
> owner = models.ForeignKey(Tenant)
> sequence_id = 
> 
> 
> I want Widget.sequence_id to work like an AutoField (that is, automatically 
> give me something unique and generally incrementing by 1) but scoped to a 
> single Widget.owner. So for instance, when Tenant A creates 3 widgets, they 
> would get sequence_ids 1, 2, and 3. Then Tenant B comes along and creates 2 
> widgets; those widgets get sequence_ids 1 and 2. The tenant/user gets no 
> control over the number, but it's something she'll see in the UI. 
> AutoNumber is out because from the perspective of a single tenant, they 
> should have sequential widget IDs. GUIDs/UUIDs are out because it needs to 
> be human-readable.
> 
> I looked through docs on AutoField and unique_together. I turned 
> StackOverflow upside down and only found this 
> , 
> which isn't quite what I want. I didn't see anything on djangopackages.com 
> that would solve my problem, though I could have missed it.
> 
> Basically, has anyone done something like this before and have a suggested 
> pattern?
> 
> Thanks!
> ~matt
> 
> -- 
> 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/37fd32e7-28dd-4c10-8451-b0d705a3e52e%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/20150113150642.3fd490a2%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Expected performance of the django development server?

2015-01-04 Thread Jani Tiainen
On Sun, 4 Jan 2015 20:41:58 -0800 (PST)
Richard Brockie <richard.broc...@gmail.com> wrote:

> Hello again,
> 
> I'm to the point in my django development that I am beginning to use 
> realistic amounts of test data. I'm using postgresql as the database 
> server, with PyCharm as my IDE, everything in a virtualenv on an SSD on an 
> Ivy Bridge Core i7 processor with 16 GB of RAM running Windows 7 64-bit. 
> 
> One disappointing thing I have just encountered is the lack of speed when 
> working with my real-world data. I'm comparing this with the same data in a 
> non-framework-based php/MySQL webapp running on XAMPP (which means apache) 
> in parallel on the same system.
> 
> With DjDT installed (Django development tools), I'm getting the following 
> stats:
> 
>- Quick to load page:SQL: 5 queries in 4 ms, Time: 76 ms
>- Slow to load page: SQL: 1189 queries in 463 ms, Time: 9754 ms
>
> From task manager, the slow to load page is making "python.exe *32" use 1 
> whole logical processor during the page load.
> 
> Are these expected response times? I'm hoping this is the result of a 
> non-optimized development server, and not the expected performance of 
> Django itself.
> 
> Any comments or advice?

By judging amount of queries of your "slow" page you probably have model(s) 
with foreign keys that you lazy load - which means that each fk is loaded 
individually from the database with separate query.

For example if you have a model that contains 4 foreign keys and you query 100 
instances (rows) you would actually invoke 1 + 4 * n queries, which in example 
case would be 401. 

Without actually knowning your code one of the first options you usually do to 
optimize queries is to use select_related and prefetch_related queryset methods 
to cut down number of queries needed.

-- 

Jani Tiainen

-- 
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/20150105080927.4cc08eac%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Django vs ExtJS

2014-12-30 Thread Jani Tiainen
On Mon, 29 Dec 2014 06:55:57 -0800 (PST)
Joris Benschop <joris.bensc...@gmail.com> wrote:

> Hi List,
> 
> I;m a data maangement specialist in a rather large multinational. I'm 
> trying to push Django as a fast development framework for front-end 
> applications of our databases. Currently the company is focusing on
> Sencha ExtJS and java solutions. Can you help me with pointers why
> Django is better? The free-as-in-beer argument is not very convincing
> by itself. 
> 

I'll give my late insight here. We're having rather large SPA's built
on top of ExtJS + Django and REST rather successfully.

Of course ExtJS and REST is really a joke - there is nothing that
really proper rest support in ExtJS, (no HATEOAS at all)

For a Django side REST tool we've been using DRF
(Django-Rest-Framework) which big gun for REST api.

Now why we picked Django over several others - We tried PHP, we
used Java for few web apps (and it's still in use). First reason was
the speed. We could implement features much faster with Python and
Django than we ever could do with Java (we did similiar apps with Java
as well but pace was definitely slower). Specially getting things
done within a reasonable time. Also lot of boilerplate code was
unnecessary. In Java we had really carefully plan every attribute and
getters and setters. Python makes lot of shortcuts there and it's much
more easier to do "magic". Though there lies a danger - you can write
Python code as Java (or even like C code) and that is not pretty
sight...

Another reason was level of complexity - even simplest Java app
(deployed on Tomcat) takes lot of efforts and "special" knowledge, not
to mention that you have to match versions you build with java versions
and complex configuration. Python is much more forgiving in those parts.

Of course we've ran a few issues on the road, like composite keys and
some "oo" features of Django ORM that were possible with Hibernate.

So current main setup in our development stack is Python (2.7), Django
(1.5), Oracle (10g and 11g), ExtJS (4.3), Dojotoolkit (1.6), OpenLayers
(2.x) and mapserver (6.x)

-- 

Jani Tiainen

-- 

Jani Tiainen

-- 
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/20141230154442.0c03e788%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

2014-12-23 Thread Jani Tiainen
On Tue, 23 Dec 2014 02:23:16 -0800 (PST)
su...@janakitech.com wrote:

> I have following model.
> 
> class CampaignTemp(models.Model):
> campaign_modules = Module.objects.filter(active=True)
> choices = 
> ...
> ... # other fields 
> 
> I get following error when I try `python manage.py`.
> ...
> File "/home/auser/aproject/src/apps/anapp/models.py", line 35, in 
> CampaignTemp
> campaign_modules = Module.objects.filter(active=True)
> ...
> django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
> ...
> 
> The code was written for Django1.6 and is being ported to 1.7. Any help 
> would be appreciated.
> 

You're doing it wrong. You should never try to access data from database when
constructing models (or load modules) since there is no guarantee that "Module" 
model
is completely initialized and working properly.

Since you don't provide more details I assume that you try to have dynamic from 
Module to
fill choices. There are two fundamental problems first is what happens above 
and second
is that campaign_modules is only evaluated _once_ in lifetime of a CampaignTemp 
model. So
if you change active status of modules they're not reflected to that list.

You need to provide more context of your model so we can help with proper 
solution.

-- 

Jani Tiainen

-- 
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/20141223152847.16290ac5%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Error: 'NoneType' object has no attribute 'strip'

2014-12-01 Thread Jani Tiainen
On Mon, 1 Dec 2014 10:20:24 -0300
Vijay Khemlani <vkhem...@gmail.com> wrote:

> Have you tried following the stacktrace that resulted in the error?
> 
> Does it fail when trying to strip the contents of the "name" field?
> 

Or maybe that library where field AutoSlug comes from isn't compatible
with your version of Django?

-- 

Jani Tiainen

-- 
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/20141201153155.67cb49bf%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Error: 'NoneType' object has no attribute 'strip'

2014-12-01 Thread Jani Tiainen
On Mon, 1 Dec 2014 04:12:45 -0800 (PST)
Danish Ali <dan...@jotixtech.com> wrote:

> Hello,
> 
> I am getting this error: Error: 'NoneType' object has no attribute 'strip'
> I have created a model and I am trying to autofill slug field in it. When I 
> save the record in database I get this error: Error: 'NoneType' object has 
> no attribute 'strip'
> 
> My model is:
> 
> from django.db import models
> from autoslug import AutoSlugField
> 
> # Create your models here.
> 
> class Shop(models.Model):
> name = models.CharField(max_length=200)
> image = models.CharField(max_length=200)
> description = models.TextField()
> slug = models.SlugField(null=True, blank=True)
> slug = AutoSlugField(populate_from='name')
> 
> 
> If I remove: slug = AutoSlugField(populate_from='name') then it works fine. 
> So, can someone tell me what is the issue here?

How are you trying to set data and trying to save to database (used commands 
would be helpful)

-- 

Jani Tiainen

-- 
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/20141201151426.2fdd643f%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Need help with unique_together - on ForeignKey and Boolean field

2014-11-17 Thread Jani Tiainen
On Sun, 16 Nov 2014 23:51:16 -0800 (PST)
ThomasTheDjangoFan <stefan.eichholz.ber...@googlemail.com> wrote:

> Hi guys,
> 
> I'd like to only be able to assign many ProcutImages to a Product, but only 
> ONE Image as a default image per product 
> (ProductImage.is_default_image=True).
> 
> I can't get this to work correnctly on Django 1.7 with a db.sqlite3: With 
> the code below I can only assign ONE Image to a Product. After that I get 
> the error "Product image with this Product und Is default image already 
> exists.".
> 
> Am I getting something wrong?
> 
> from django.db import models
> 
> class Product(models.Model):
> title = models.CharField(max_length=255)
> 
> is_active = models.BooleanField(default=True)
> 
> 
> class ProductImage(models.Model):
> product = models.ForeignKey(Product)
> 
> image = models.ImageField(upload_to='products/images/')
> 
> is_default_image = models.BooleanField(default=False,null=False,blank=
> False)
> 
> class Meta:
> # A product can have multiple ProductImages, but only one of them 
> can be the "default"-image
> unique_together = ('product', 'is_default_image')
> 
> I would be really thankful for some tips.

Well boolean field can have only two values: "true" or "false".

Now your unique_together defines that for "product" combined with 
"is_default_image" must be unique. Which means that for each product you can 
have _two_ images, one where is_default_image is true and one where 
is_default_image is false. And this is forced on database level as well.

But apparently that is what you intended to do. There isn't really one single 
solution for your problem.

-- 

Jani Tiainen

-- 
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/20141117122459.5de8b80b%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Run some code after Model Save completes (and after database is updated)

2014-10-15 Thread Jani Tiainen
On Tue, 14 Oct 2014 10:00:17 -0700 (PDT)
Spiros Mouzakitis <mouzakitis@gmail.com> wrote:

> Hi,
> 
> -I am looking for an elegant, and universal way to add some code AFTER the 
> saving of a model and after of course the database is updated with changes.
> -I have tried post_save signals, but the transaction is still on, the 
> entries do not exist in database
> -I have tried overriding save in models.py, but even if i put  the code 
> after.super(MyModel, self).save(*args, **kwargs), the database is still 
> not updated until the save function completes.

Database is definitely updated after save has completed and post_save signal is 
fired.

One thing that may interfere at least MySQL uses "repeatable read" (default) 
transcation isolation level
meaning that select will return db state when transaction opened. Changing 
isolation to "read committed" 
should improve situation there.

-- 

Jani Tiainen

-- 
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/20141016073835.14578089%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Django: How to apply filter on geometry type using GeoDjango QuerySet

2014-10-14 Thread Jani Tiainen
On Mon, 13 Oct 2014 23:34:04 -0700 (PDT)
Shoaib Ijaz <shoaib.ij...@gmail.com> wrote:

> 
> 
> I am trying to convert a SQL into Django Query:
> 
> SELECT * from tbl_name where geometrytype(geometry) LIKE 'POINT';
> 
> I have searched on it but cannot find any geometry type function.
> 

You can't, at least not with current Django versions. Geodjango assumes
that geometry column contains just one type of a geometries.

But you should be able to use .raw() query to get what you want to.

-- 

Jani Tiainen

-- 
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/20141014101328.5d20ed42%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: query join tables

2014-10-13 Thread Jani Tiainen
On Sun, 12 Oct 2014 22:01:51 -0700 (PDT)
dk <demi...@gmail.com> wrote:

> I have this 2 models
> 
> class Choice(models.Model):
> restaurant = models.ForeignKey(Restaurant)
> person = models.ForeignKey(Person)
> date = models.DateField("time published")
> time = models.TimeField("date published")
> 
> class Person(models.Model):
> name = models.CharField(max_length=100)
> last_name = models.CharField(max_length=100)
> email = models.EmailField()
> 
> and I would like to be able to see check if in a certain date, a certain 
> person does exist in the record.
> I am currently querying the date first.
> 
> date_query = Choice.objects.filter(date=dater)
> for i in date_query:
> if i.person_id == to_email_i_am_looking:
> 
> might be another way to chain the querys? 
> kinda
> 
> SELECT person  FROM choice JOIN people
> ON choice.person_ID=person+ID; 
> WHERE date= today and person=someone
> ?
> 
> I read about select_related that use the ForeignKey,  but I have 2 in my 
> case,  the person and the restaurant,  does it loop on bouth?

You can leverage reverse relation managers rather easily:

If you do have a person available already you can do the following:

choices_for_person_on_date = person.choice_set.filter(date=dater)

-- 

Jani Tiainen

-- 
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/20141013141555.422f4b4a%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Is there anything similar to phpmyadmin

2014-09-23 Thread Jani Tiainen
I personally like DBeaver, since it can handle several types of DBMSes out of 
the box.
And it's free.

There are prebuilt packages for pretty much any major os/distribution.

On Mon, 22 Sep 2014 19:37:26 -0700 (PDT)
Yuan-Liang Tang  wrote:

> Thanks, but I'd like to use something open and free ;-)
> Per your suggestions about native apps, MySQL Workbench, included in 
> Ubuntu's Software Center, seems to be a good solution?
> 
> Thangs a lot.
> 
> 
> alTus於 2014年9月23日星期二UTC+8上午7時21分36秒寫道:
> >
> > I've come to the fact that standalone apps on your client computer are 
> > much more handy for db management.
> > All you need is to set up ssh tunnel to your server.
> > Native apps generally work faster and also allow you not to waste time 
> > setting up _stuff_ on the server.
> >
> > SQLYog is a very good program for mysql (but it's not free).
> > Still there're a lot of alternatives.
> >
> > воскресенье, 21 сентября 2014 г., 5:38:15 UTC+4 пользователь Yuan-Liang 
> > Tang написал:
> >>
> >> I'd like to know if there is anything/anyway similar to phpmyadmin for 
> >> managing MySQL DBs in a Django project or in the Python environment. Any 
> >> suggestions?
> >>
> >> django-mysql-manage seems to be dead.
> >>
> >> https://pypi.python.org/pypi/django-mysql-manager/0.1.2
> >>
> >>
> 
> -- 
> 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/fa94db3b-b061-4699-a1b1-42c3c67a6e7a%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/20140923132703.23e84c83%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Install Django Apps via Admin Interface

2014-09-12 Thread Jani Tiainen
Hi,

It seems that you're confusing Django to to be something that it isn't.

Django is a web application framework. In short meaning that it is set of 
(Python) libraries
that are used to build web applications. Django app is usually reusable piece 
of code that brings
some (usually common) functionality within framework ecosystem. 

But Django is not CMS like tool where you really install stuff just by clicking 
a button and it magically appears.
There exists few CMS solutions built on top of Django - I've never used them so 
I can't vouch for any of them.

In simplest case installing django app is really just by adding a module in 
INSTALLED_APPS in settings.py 
but many times it's much more - data migrations, configuring external services, 
collecting static
files, deciding url routing. Maybe even installing system packages that 
requires root access.

And you would expect that to happen just through admin? Would you trust your 
users really to do all
that - basically giving full control what users installs to your system without 
discretion? 

-- 

Jani Tiainen

On Fri, 12 Sep 2014 11:26:56 +0200
Thomas Güttler <h...@tbz-pariv.de> wrote:

> 
> 
> Am 10.09.2014 um 11:07 schrieb Avraham Serour:
> > you can't, you would need to write something yourself capable of doing this.
> 
> that's sad.
> 
> > in any case why would you want to do that?
> 
> Convenience. It would be great if some admin plugin could do this: Connect to 
> pypi and list all
> available packages which can be installed into django ...
> 
> I see a lot of **not DRY** docs in django packages: Over and over again the 
> same instructions: Add "foo" to 
> INSTALLED_APPS 
> 
> > adding an app to a project may involve not only installing the python 
> > package
> > and adding the app to INSTALLED_APPS, but also adding configurations to 
> > settings.py, running syncdb/migrate and
> > reloading the instance.
> 
> I guess django experts have a good solution for this small technical problem.
> 
>Thomas
> 
> 
> -- 
> Thomas Güttler
> http://thomas-guettler.de/
> 
> -- 
> 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/5412BC60.2080705%40tbz-pariv.de.
> 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/20140912125341.34c70c58%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: ASP .NET web service and Django

2014-05-26 Thread Jani Tiainen
You might be interested in suds library, it's basically lightweight SOAP stuff, 
it may work or it may not.
All depends quality of WSDL you do have.

And to my knowledge getting Django to run on IronPython requires some
hacks...

On Mon, 26 May 2014 04:09:19 -0700 (PDT)
shar100101  wrote:

> Unfortunately Tastypie is not solution for me, because it uses Rest. I am 
> using IronPython to run website and I still have not found solution to read 
> Soap/Rest requests with IronPython.
> 
> I was hoping that output form .Net service, sent using HTTP, can be used in 
> Django. I tried using WebRequest class but it didn't work.
> 
> -- 
> 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/091eda56-74a2-4b41-aa15-4f9a0c465daa%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/20140526141936.7140a546%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: django and oracle

2014-05-16 Thread Jani Tiainen
On Thu, 15 May 2014 00:07:47 -0700 (PDT)
"J. D." <john.arnold.dav...@gmail.com> wrote:

> 
> On Wednesday, 14 May 2014 21:08:11 UTC+4, Avraham Serour wrote:
> >
> > it looks like your error occurs when using django ORM with oracle, but in 
> > the beginning of your email you mention that you don't want to use it, so 
> > what's the problem here?
> >
> >  
> I want to reuse established connection with the Oracle DB (I thought django 
> connection helps with that out of the box). This is my first experience 
> with Oracle DB.
> 
> --
> 
> @Jani Tiaine, thanks for the help, but it doesn't work:
> 
> "ora_cur = connection.connection.cursor()  # See double connection stuff"
> 
> Exception Type: AttributeError  Exception Value: 
> 
> 'NoneType' object has no attribute 'cursor'

Oh sorry about that. It seems that connection attribute is only populated
when you have connection opened for something.

So you have to do initial dummy stuff:

connection.cursor()  # Opens connection

curs = connection.connection.cursor()   # Get raw cursor

Or, alternatively as a one liner:

curs = connection.cursor().cursor.cursor  # Get raw cursor


Hope that helps.

-- 

Jani Tiainen

-- 
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/20140516101623.130d069a%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: django and oracle

2014-05-14 Thread Jani Tiainen
On Thu, 15 May 2014 07:02:08 +0300
Jani Tiainen <rede...@gmail.com> wrote:

> On Wed, 14 May 2014 07:54:58 -0700 (PDT)
> "J. D." <john.arnold.dav...@gmail.com> wrote:
> 
> > Can someone help me with cx_Oracle and Django?! :)
> > 
> > I have Oracle DB 11.2 with many PLSQL-procedures in it that return cursor 
> > with various output. I want to work with them without django ORM and 
> > directly call them.
> > 
> > First of all i ran my python code without django, with the cx_Oracle driver 
> > and everything works well.
> > 
> > conn = cx_Oracle.connect('user', 'pass')
> > ora_cur = conn.cursor()
> > l_cur = ora_cur.var(cx_Oracle.CURSOR)
> > l_query = ora_cur.callproc('user.VIEW.procedure_with_cursor', (None, None, 
> > None, None, l_cur,))  #None -  "*in*" parameters and l_cur - *out * 
> > l_query[0].fetchall()
> > 
> > 
> > but with the django and same code, i got the error:
> > 
> > import cx_Oracle
> > from django.db import connection
> > 
> > ora_cur = connection.cursor()
> > ora_cur.execute("SELECT * from v$version") #it works
> > 
> > l_cur = ora_cur.var(cx_Oracle.CURSOR)  #-> *Error: 
> > *Variable_TypeByPythonType(): 
> > unhandled data type
> > l_query = ora_cur.callproc('user.VIEW.procedure_with_cursor', (None, None, 
> > None, None, l_cur,))
> > l_query[0].fetchall()
> > 
> > 
> > Django Version: 1.6.4  Exception Type: NotSupportedError  Exception Value: 
> > 
> > Variable_TypeByPythonType(): unhandled data type
> > 
> > 
> > 
> >  Python Version: 2.7.3cx_Oracle 5.1.2
> > 
> 
> You're seeing that error because cursor returned from Django connection is not
> actually cx_Oracle cursor but a wrapper that has similar methods. That is 
> done to
> overcome different binding variable types and to use %s (oracle uses :name 
> format)
> 
> You should be able to get pure cx_Oracle cursor by calling:
> 
> connection._cursor()

Sorry, my bad. You can get pure cx_Oracle connection from:
connection.connection

>From there you can do:

connection.cursor().

So to rewrite your example in "django" way:

import cx_Oracle
from django.db import connection
 
ora_cur = connection.connection.cursor()  # See double connection stuff
ora_cur.execute("SELECT * from v$version") #it works
 
l_cur = ora_cur.var(cx_Oracle.CURSOR)
l_query = ora_cur.callproc('user.VIEW.procedure_with_cursor', (None, None, 
None, None, l_cur,))
l_query[0].fetchall()


-- 
 
Jani Tiainen

-- 
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/20140515072320.5f65715c%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: django and oracle

2014-05-14 Thread Jani Tiainen
On Wed, 14 May 2014 07:54:58 -0700 (PDT)
"J. D." <john.arnold.dav...@gmail.com> wrote:

> Can someone help me with cx_Oracle and Django?! :)
> 
> I have Oracle DB 11.2 with many PLSQL-procedures in it that return cursor 
> with various output. I want to work with them without django ORM and 
> directly call them.
> 
> First of all i ran my python code without django, with the cx_Oracle driver 
> and everything works well.
> 
> conn = cx_Oracle.connect('user', 'pass')
> ora_cur = conn.cursor()
> l_cur = ora_cur.var(cx_Oracle.CURSOR)
> l_query = ora_cur.callproc('user.VIEW.procedure_with_cursor', (None, None, 
> None, None, l_cur,))  #None -  "*in*" parameters and l_cur - *out * 
> l_query[0].fetchall()
> 
> 
> but with the django and same code, i got the error:
> 
> import cx_Oracle
> from django.db import connection
> 
> ora_cur = connection.cursor()
> ora_cur.execute("SELECT * from v$version") #it works
> 
> l_cur = ora_cur.var(cx_Oracle.CURSOR)  #-> *Error: 
> *Variable_TypeByPythonType(): 
> unhandled data type
> l_query = ora_cur.callproc('user.VIEW.procedure_with_cursor', (None, None, 
> None, None, l_cur,))
> l_query[0].fetchall()
> 
> 
> Django Version: 1.6.4  Exception Type: NotSupportedError  Exception Value: 
> 
> Variable_TypeByPythonType(): unhandled data type
> 
> 
> 
>  Python Version: 2.7.3cx_Oracle 5.1.2
> 

You're seeing that error because cursor returned from Django connection is not
actually cx_Oracle cursor but a wrapper that has similar methods. That is done 
to
overcome different binding variable types and to use %s (oracle uses :name 
format)

You should be able to get pure cx_Oracle cursor by calling:

connection._cursor()

-- 

Jani Tiainen

-- 
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/20140515070208.6b8cda16%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Complex query

2013-09-08 Thread Jani Tiainen
Problem is that you have to be able to express it in SQL. And thus ther is not 
much you can do in SQL to get what you actually wanted.

Considering amount of the data fetched - it's relatively low query count and 
unless you're hitting very busy site you wont notice much of difference doing 
this in 6 queries.

One to fetch last 5 topics and then 5 to get that 20 latest posts per topic.

When you later may hit really busy site you can cache list for a short time to 
relieve load on db.

On Sun, 8 Sep 2013 14:13:09 -0700 (PDT)
Yegor Roganov  wrote:

> I found out this is a so called "top n per group" problem and it's not that 
> easy to implement in django. Maybe someone could help me to find another 
> way (for example, alter the schema in some 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.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Load base test data outside Django framework

2013-09-02 Thread Jani Tiainen
Hi,

I would like to conduct unit testing using complex test data that I do not want 
to reload for every test again and again.

In broken down steps to what I would like to do:

 1. Create test database
 2. Load initial data using database's own tools instead of Django fixtures
 3. Record state of the database
 4. Load per test data if needed
 5. Run a test - one of the CRUD ops for example
 6. Reset database to state recorded in step 3
 7. Jump to step 4 if there is more tests waiting to be run
 8. Destroy test database


To my understanding I need custom test runner that creates and loads up 
database,

Next thing that I need is to to create wrapping transaction that I will always 
rollback in the end of test case cycle, and finally drop test user off along 
the database. 

Any pointers and ideas are welcome. I would prefer to have "universal" solution 
that is applicable to all supported django backends, though Oracle and 
PostgreSQL (+ PostGIS) is my main target. Sqlite (+ SpatiaLite) would be a 
bonus.

-- 

Jani Tiainen

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: serve static files

2013-08-26 Thread Jani Tiainen
If you're using contrib.staticfiles app, your DEBUG is True and you're using 
runserver django automagically maps (overrides) your staticfile serving.

If you want to manually add staticfile serving, you have to give --nostatic 
parameter to runserver to omit all magic that happena automatically.


On Mon, 26 Aug 2013 07:58:38 -0700 (PDT)
Wesley Ni <wesley.ni...@gmail.com> wrote:

> I hit an issue when trying serve static files.
> 
> In settings, debug is True, and with the followinig:
> STATIC_ROOT = os.path.join(freelancer_path,"staticfiles")
> STATIC_URL = '/staticfiles/'
> 
> urls.py:
> (r'^staticfiles/(?P.*)$','django.contrib.staticfiles.views.serve',
> {'document_root' : STATIC_ROOT,'show_indexes' : True}),
> 
> Problem is, when accessing http://127.0.0.1:8000/staticfiles/, I got this:
> Page not found (404)
> Request Method: GET
> Request URL: http://127.0.0.1:8000/staticfiles/
> 
> Why? I thought I would get folder indexes because I set show_indexes to 
> True.
> 
> And, later, I find that, if I set the url pattern prefix not same to 
> STATIC_URL, 
> say, maybe :
> (r'^files/(?P.*)$','django.contrib.staticfiles.views.serve',
> {'document_root' : STATIC_ROOT,'show_indexes' : True}),
> And, then, http://127.0.0.1:8000/files/ is OK to show folder lists.
> 
> Could anyone help explain and fix?
> 
> Thanks.
> Wesley
> 
> -- 
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 

Jani Tiainen

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django signals to all connections?

2013-08-20 Thread Jani Tiainen
Hi,

Well it seems that you have understood things a bit incorrectly.

First at all, only logged in user is the one accessing some page (a view) from 
Django system.

After that there is nobody logged in traditional sense - there is no simple way 
to detect that user closed browser and was "logged out" nor there is no simple 
way to tell that who is actually even logged in. Most "logged in" counters do 
rely on "less than X time from last action" means active user, whether or not 
that is true.

So what you asked is not possible to do that way. 

That doesn't mean that you can't do it - it would just require a bit more work.

You need two things for that - first you need means to actually store message 
somewhere and secondly you need some mechanism that you check unread messages 
per user return messages in some proper format if there are unread messages and 
mark them read somehow.

That covers serverside work pretty well. Nothing magic just a bit of coding 
work.

In a client you have few options - as you asked for live update you would have 
to have (timed) piece of javascript that in certain intervals pulls messages 
(if any) from server.

There exists other techniques (server push, BOSH, Comet, websockets) as well 
but that is pretty much simplest one to implement.

If you're lucky you can find good examples by gooling for "django web chat" or 
similiar.

On Mon, 19 Aug 2013 06:48:33 -0700 (PDT)
Gerd Koetje  wrote:

> but can it also update a message on a page where that user is without 
> reloading the page?
> 
> lets say user 1 is on page http://www.domain.com/acertainview/
> 
> and at that moment i start a signal as admin with the text hello there
> Can i update the text on his page to that text (live)
> 
> 
> Op maandag 19 augustus 2013 06:29:45 UTC+2 schreef Gerd Koetje:
> >
> > Is is possible to start an event at all connected users with signals?
> > If this is possible can someone show me an example of it.
> >
> >
> > Greetz
> > Gerd
> >
> >
> 
> -- 
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Representing infinity or "no limit" in an integer field?

2013-08-20 Thread Jani Tiainen
On Mon, 19 Aug 2013 11:14:54 -0700 (PDT)
Jason Arnst-Goodrich <goodri...@gmail.com> wrote:

> 
> >
> > Problem is that usually databases aren't very fast to search NULL values 
> > so if you have to for example produce often list of products that you can 
> > buy "infinite amount", you would like to consider using value(s) that don't 
> > conflict from valid set of values.
> 
> 
> I'm pretty sure that's not true.

My knowledge is limited per implementation but as far as I know, standard 
implementation is not to include NULL's (since NULL means "does not exist").

I think pretty latest PostgreSQL can use indexes to filter NULL values as well 
(doesn't have facility to store them though). Oracle since 11g has option to 
include null values in the index.

MySQL uses table statistics to determine are NULL values indexed or not.

For the rest I don't have knowledge about. 

That doesn't remove the fact that there will be a limit for ordering one time - 
though I would be happy to know what "unlimited" amount of ordering would mean 
and how to actually it would be implemented and what's the real world use 
case...

> +1 to store as Null. 
>
> On Monday, August 19, 2013 1:07:27 AM UTC-7, Jani Tiainen wrote:
> >
> > On Mon, 19 Aug 2013 00:39:09 -0700 (PDT) 
> > Victor Hooi <victo...@gmail.com > wrote: 
> >
> > > Hi, 
> > > 
> > > I have a Django IntegerField that I'm using to store the purchase limit 
> > for 
> > > a product. 
> > > 
> > > purchase_limit = models.IntegerField() 
> > > 
> > > 
> > > I also need to represent no limit (i.e. infinity) as well in that field. 
> > > 
> > > I was thinking of just using NULL to represent no limit. 
> > > 
> > > purchase_limit = models.IntegerField(blank=True, null=True) 
> > > 
> > > 
> > > Zero would have a meaning for this field (you can't buy any), however 
> > > negative numbers don't have any meaning. 
> > > 
> > > Hence, another option is just to use say, -1 as the value to represent 
> > no 
> > > limit. 
> > > 
> > > Any thoughts on either option, or which one is more "correct"? 
> >
> > From mathematical point integers forms an infinite (countable) set. Though 
> > in computer science interger is usually a finite set. So what you need is 
> > just define a logic. Note that this also makes impossible to enforce 
> > "unlimited" amount to buy so there will definitely be some maximum amount 
> > you can really buy. 
> >
> > NULL is usually interpreted as "no value defined" which would suit well in 
> > that sense. Problem is that usually databases aren't very fast to search 
> > NULL values so if you have to for example produce often list of products 
> > that you can buy "infinite amount", you would like to consider using 
> > value(s) that don't conflict from valid set of values. 
> >
> > I personally would pick max value while leaving NULL to mean "no value 
> > defined". 
> >
> > -- 
> >
> > Jani Tiainen 
> >
> 
> -- 
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Representing infinity or "no limit" in an integer field?

2013-08-19 Thread Jani Tiainen
On Mon, 19 Aug 2013 00:39:09 -0700 (PDT)
Victor Hooi <victorh...@gmail.com> wrote:

> Hi,
> 
> I have a Django IntegerField that I'm using to store the purchase limit for 
> a product.
> 
> purchase_limit = models.IntegerField()
> 
> 
> I also need to represent no limit (i.e. infinity) as well in that field.
> 
> I was thinking of just using NULL to represent no limit.
> 
> purchase_limit = models.IntegerField(blank=True, null=True)
> 
> 
> Zero would have a meaning for this field (you can't buy any), however 
> negative numbers don't have any meaning.
> 
> Hence, another option is just to use say, -1 as the value to represent no 
> limit.
> 
> Any thoughts on either option, or which one is more "correct"?

>From mathematical point integers forms an infinite (countable) set. Though in 
>computer science interger is usually a finite set. So what you need is just 
>define a logic. Note that this also makes impossible to enforce "unlimited" 
>amount to buy so there will definitely be some maximum amount you can really 
>buy.

NULL is usually interpreted as "no value defined" which would suit well in that 
sense. Problem is that usually databases aren't very fast to search NULL values 
so if you have to for example produce often list of products that you can buy 
"infinite amount", you would like to consider using value(s) that don't 
conflict from valid set of values.

I personally would pick max value while leaving NULL to mean "no value defined".

-- 

Jani Tiainen

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: ImportError: No module named 'exceptions' - Python3

2013-08-12 Thread Jani Tiainen
Hi,

In Python 3 exceptions module was removed and all standard exceptions were 
moved to builtin module. Thus meaning that there is no more need to do explicit 
import of any standard exceptions.


On Mon, 12 Aug 2013 10:51:32 +0530
abhijeet shete  wrote:

> Hi Folks,
> 
> I ported my project from python2.7 to python3 using 2to3 module. One of
> my class is inherited from Exception class, but after porting to python3 i
> am getting *No module named 'exceptions'  *error.
> 
> My class looks something like this :-
> 
> *from exceptions import Exception*
> *class A(Exception):*
> *def __init__(self, value=None):*
> *self.value = value*
> *
> *
> And the error which I am getting is
> *
> *
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: No module named 'exceptions'
> 
> 
> I tried to import exceptions in python3 shell but there also I am getting
> same error.
> Is there any problem with my code or did I missed something while porting
> or python3 itself has some problem while importing exceptions ?
> 
> 
> Thanks and Regards.
> Abhijeet Shete
> 
> -- 
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Testing with legacy data

2013-08-05 Thread Jani Tiainen
Hi,

I've legacy database that is rather large (around 300MB) containing lot more 
than just data (triggers, stored procedures and such).

Now how I can test with such a data? Preferably I would like to load data to 
database, run test, rollback changes and run a next test.

But I really wouldn't like to recreate database from the scratch everytime or 
not to import data every time. 

Any suggestions how I could proceed?

-- 

Jani Tiainen

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: User Permissions

2013-07-30 Thread Jani Tiainen
On Tue, 30 Jul 2013 16:39:27 -0300
Carlos Leite <cadu...@gmail.com> wrote:

> Django do not have a "per-row" permission system in the box.
> You will have to create that by yourself.

That is slightly incorrect - Django _does_ have foundation for object (row) 
level permission system. There is just no default implementation in standard 
auth
module. User methods get_group_permissions, get_all_permissions, has_perm and 
has_perms does accept optional second parameter "obj" which if set anything 
else but None will check permission for spesific object instead of model.

<https://docs.djangoproject.com/en/1.5/topics/auth/customizing/> contains more 
info about customizing authentication backend.
 
> You may start adding something like "owner" to your content type.
> this field will be somthing like
> 
>   owner = models.ForeignKey(User)
> 
> then, based on "request.user" in your views (for instance),
> you may filter objects using .objects.filter(owner=requet.user)
> 
> hope that helps.
> 
> 
> 
> On Tue, Jul 30, 2013 at 12:39 PM,  <ghin...@screenscene.ie> wrote:
> > Hi All,
> >
> > I have a very simple django site.
> > The site allows the administrator to create a model which contains 5 text
> > items and then stores that to the sqlite database.
> > I have also created a user login page from a tutorial on youtube.
> > I want to be able to control which model the logged in user has access to.
> > For instance I want user "John" to be able to see logged model entries 1-5
> > and not 6-7.
> > Is this simple? How should I go about setting permissions?
> >
> > Any help is appreciated. If you would like specific code please ask.
> >
> > Thanks
> >
> >
> >
> >
> > --
> > 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.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
> 
> 
> 
> -- 
> 
> Cadu Leite
> twitter: @cadu_leite
> http://people.python.org.br/
> 
> -- 
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 

Jani Tiainen

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django not enforcing blank=False on a model

2013-07-29 Thread Jani Tiainen
On Mon, 29 Jul 2013 18:14:50 -0700 (PDT)
Knight Samar <knightsa...@gmail.com> wrote:

> Hi,
> 
> I have a model
> 
> > from django.db import models
> >
> > class Organization(models.Model):
> > name = models.CharField(max_length=100,
> > blank = False,  #mandatory
> > help_text = "Name of your Organization",
> > verbose_name = '',
> > unique = True,
> > primary_key = True,
> > )
> >
> >
> and a piece of code
> 
> > from organization.models import Organization
> > o = Organization.objects.create() 
> > o.save() 
> 
> 
> which works *without raising an IntegrityError!* And the following also 
> works just the same!
> 
> > from organization.models import Organization
> > o = Organization() 
> 
> o.save() 
> 
> 
> I am using SQLite3(SQLite 3.7.9 2011-11-01 00:52:41 
> c7c6050ef060877ebe77b41d959e9df13f8c9b5e) as the database backend and it 
> shows the following as the schema:
> 
> CREATE TABLE "organization_organization" ( "name" varchar(100) NOT NULL 
> > PRIMARY KEY ); 
> 
>  
> Even if SQLite3 was buggy, shouldn't Django itself enforce the constraint 
> on ORM layer ?
> 
> I have deleted .pyc files and also the .sqlite3 file before testing again. 
> I am using Django 1.5.1
> 
> What am I missing ? Why is Django *NOT* enforcing blank=False ?

Blank is for input fields. It means that when validating form input value 
cannot be blank. And by default django uses empty string to denote empty 
charfield, not null. (Except Oracle)

>From 
><https://docs.djangoproject.com/en/1.5/ref/models/fields/#django.db.models.Field.blank>:
"Note that this is different than null. null is purely database-related, 
whereas blank is validation-related. If a field has blank=True, form validation 
will allow entry of an empty value. If a field has blank=False, the field will 
be required."

Also, you should note that .save() doesn't imply running validation 
<https://docs.djangoproject.com/en/1.5/ref/models/instances/#validating-objects>

-- 

Jani Tiainen

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How i can get real value of ForeingKey?

2013-06-26 Thread Jani Tiainen
On Wed, 26 Jun 2013 10:47:09 -0300
Mário Idival <marioidi...@gmail.com> wrote:

> Good morning,
> Guys, how can I get the real value of a ForeignKey?
> Examples:
> class A (models.Model):
>  field1 = models.CharField (max_length = 10)
> 
> class B (models.Model):
>   field_b1 = models.CharField (max_length = 10)
>   a_field = models.ForeingKey (A)
> 
> right, now imagine that on the bench, table A has saved:
> field1 = "world"
> and B is saved in the table:
> field_b1 = "hello"
> a_field = 1
> 
> Well, how can I get the real value of a_field (which is world)? But there's
> a catch, I wanna do this for the entire table B, if there is more fields
> saved in the bank.
> 

Real value of a_field is an object instance type of the class (model) A.

So there is no magic "value". Even you see visible one field in your model 
(field1) your model actually contains already two fields: id and field1. In 
your case field1 can contain any 10 character string.

How you want to represent your related object is totally a different story and 
there is not single correct answer - it all depends how you want to represent 
it.

-- 

Jani Tiainen

"Impossible just takes a little longer"

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: how to change the root url of a project?

2013-06-26 Thread Jani Tiainen
On Wed, 26 Jun 2013 04:40:26 -0700 (PDT)
yang guang <yg54...@gmail.com> wrote:

> HI, all
> I'm a beginner of django.
> Here I start a project named mysite. And I can browse it with 
> http://127.0.0.1:8000. But now I want to change it to 
> http://127.0.0.1:8000/mysite/ and stll keep my url mapping as url(r'^$', 
> 'index') instead of (r'^mysite/$', 'index'). Because there are some other 
> apps in the project.
> 
> Could anyone help me figure it out? Thanks in advance.

When running Django devserver and connecting to it directly there is a little 
you can do.

In real case you'll have some server to keep django up and running and there 
you have option to use suburls as you want to. But it requires setting up real 
frontend server like nginx, apache or similiar.

-- 

Jani Tiainen

"Impossible just takes a little longer"

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django tutorial part 1 (Using the api, p.choice_set.all() displays choices in reverse order)

2013-06-18 Thread Jani Tiainen
On Mon, 17 Jun 2013 21:34:00 -0700 (PDT)
Dandall Von <duknov...@gmail.com> wrote:

> I have successfully setup Django with postgreSQL and everything is fine 
> except for a minor problem.
> 
> One the very last section of the the tutorial part 1 where we type 
> p.pchoice_set.all(), it displays the
> choices in the reverse order.  
> 
> For example I get: Just hacking again, The sky, Not much
> Instead of: Not much, The sky, Just hacking again
> 
> I typed it in the order it shows and still I get a reverse order.
> 
> Any ideas?

That is how databases do work.

Default ordering is "no ordering". So you get results in no particular order.

To have consistent fixed ordering you need to tell it somehow to database 
backend, in Django it's done by .order_by() [1]

And then you have to select field you sort by. In case of tutorial there is not 
actually any good field to sort by in Choice-model.


[1] https://docs.djangoproject.com/en/1.5/ref/models/querysets/#order-by
-- 

Jani Tiainen

"Impossible just takes a little longer"

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: database -> model -> charting

2013-06-07 Thread Jani Tiainen
On Fri, 7 Jun 2013 01:20:27 -0700 (PDT)
tony gair <tonytheg...@gmail.com> wrote:

> 
> 
> I would like to hear peoples opinions on third party django charting apps, 
> with various considerations. My primary consideration would ease of use by 
> a django noob. Thanks
>

You can quite easily use pretty much any JS charting libraries. Google Charts 
for example. And pretty much any JS framework you pick do seem to have some 
kind of a charting library available.

Simplest way in most cases is to render data for char as a JSON (which in turn 
can be uses as-is in for JS)

-- 

Jani Tiainen

"Impossible just takes a little longer"

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django foreing keys joins

2013-06-06 Thread Jani Tiainen
That is how Django works. 

So as you see, django makes query where it compares _joined_ table id as a 
null. To make it happen (left outer) join must happen, otherwise it wouldn't 
return any rows.

I agree that Django _could_ do a better and optimize query so that it would 
query instead of underlying fk field as a null value, though that would not be 
simple since a you know, filters may be chained and in case of chaining 
rewriting whole query would require quite a bit of reworkings.

If you absolutely know that your query stops there you can use underlying id 
field for faster testing:

>>> print Counter.on_medicos.filter(loc_id__isnull=True).only('id').query

That should return what you might have been expecting.

-- 

Jani Tiainen

"Impossible just takes a little longer"

On Thu, 6 Jun 2013 01:05:32 +0200
Àlex Pérez <alex.pe...@bebabum.com> wrote:

> Can someone tell me why the or in that query:
> print Counter.on_medicos.filter(loc__isnull=True).only("id").query
> 
> ""SELECT `web_counter`.`id` FROM `web_counter` LEFT OUTER JOIN
> `locations_localidad` ON (`web_counter`.`loc` = `locations_localidad`.`id`)
> WHERE (`web_counter`.`mode` = 1  AND `locations_localidad`.`id` IS NULL)"""
> 
> The orm is making a JOIN?? i can't understant!
> 
> The foreignkey loc is nullable and blank, i don't understant why making a
> filter the orm is performing the join and making an exclude the ORM is not
> performing the JOIN...
> 
> print Counter.on_medicos.exclude(loc__isnull=True).only("id").query
> SELECT `web_counter`.`id` FROM `web_counter` WHERE (`web_counter`.`mode` =
> 1  AND NOT (`web_counter`.`loc` IS NULL))
> 
> Thank's!
> 
> -- 
> Alex Perez
> alex.pe...@bebabum.com
> 
>  *bebabum* be successful
> 
> c/ Còrsega 301-303, Àtic 2
> 08008 Barcelona
> http://www.bebabum.com
> http://www.facebook.com/bebabum
> http://twitter.com/bebabum
> 
> This message is intended exclusively for its addressee and may contain
> information that is confidential and protected by professional privilege.
> If you are not the intended recipient you are hereby notified that any
> dissemination, copy or disclosure of this communication is strictly
> prohibited by law.
> 
> Este mensaje se dirige exclusivamente a su destinatario y puede contener
> información privilegiada o confidencial. Si no es vd. el destinatario
> indicado,
> queda notificado que la utilización, divulgación y/o copia sin autorización
> está prohibida en virtud de la legislación vigente.
> 
> Le informamos que los datos personales que facilite/ha facilitado pasarán a
> formar parte de un fichero responsabilidad de bebabum, S.L. y que tiene
> por finalidad gestionar las relaciones con usted.
> Tiene derecho al acceso, rectificación cancelación y oposición en nuestra
> oficina ubicada en c/ Còrsega 301-303, Àtic 2 de Barcelona o a la dirección
> de e-mail l...@bebabum.com
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Dump LineString GEOM to Point GEOM (One Model To Another)

2013-05-31 Thread Jani Tiainen
On Wed, 29 May 2013 07:13:04 -0700 (PDT)
kpurdon <kylepur...@gmail.com> wrote:

> Is it possible, outside of using a raw SQL query (PostGIS/PostgreSQL) to do 
> a GEOM dump.
> 
> I have a table (model) where 1 row is 1 LineString and I need to dump that 
> table into another table (model) where 1 row is 1 point from the LineString.
> 
> Raw SQL would be something like:
> 
> SELECT geom AS points FROM ST_DumpPoints((SELECT fl_line FROM 
> greenland.line_paths WHERE ...));
> 
> In this case line_paths is the LineString table and fl_line the LineString 
> GEOM.
> 
> How can I do this within GeoDjango w/o using rawSQL and bypassing the 
> models?

Linestrings do have coord_seq property that you can iterate over and generate 
point geometries form that and save to another table.

-- 

Jani Tiainen

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Testing with complex database setups

2013-05-27 Thread Jani Tiainen
Bummer... I whish I could have gotten away with Django test framework but it 
seems that custom testrunner would be the way. Have to check my options really.

On Fri, 24 May 2013 03:23:44 -0700 (PDT)
akaariai <akaar...@gmail.com> wrote:

> On 23 touko, 15:09, Jani Tiainen <rede...@gmail.com> wrote:
> > Hi,
> >
> > I've product that uses complex setup scripts - tens of SQL scripts that 
> > creates tables, views, complex triggers, grants permissions and such and 
> > finally populates database with some pre-data.
> >
> > So how I should proceed with unit testing with database like that, since 
> > some operations rely heavily that there really exists all that 
> > trigger-function mess in the database? So that I don't need everytime to 
> > start from the scratch but from some known state of the db?
> 
> I have some code I run my tests by the doing the following:
>   1. dump schema + some data from production
>   2. create test database by loading the dump.
>   3. Apply any migrations I have (these are plain SQL scripts, no
> South involved here)
>   4. run tests using SimpleTestCase or plain unittest TestCases.
> 
> So, I am not using Django's testing framework at all. There are two
> reasons: 1. I haven't found a nice way to create the database with
> custom scripts etc. loaded. 2. Django's test framework likes to flush
> all data from the database. This doesn't fit my needs.
> 
> So, I suggest that you either hack a custom test runner for Django, or
> just run tests without Django's testing framework. There might exists
> something reusable in the ecosystem for this use case.
> 
> It would be nice to have something that allows easy testing this way
> in Django. The problem is that once you enter complex database setups
> domain it is hard to find a minimal useful feature set.
> 
> Unfortunately I don't have anything reusable for running tests this
> way, my scripts for managing the above steps are too hacky to reuse.
> 
>  - Anssi
> 
> -- 
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Testing with complex database setups

2013-05-23 Thread Jani Tiainen
Hi,

I've product that uses complex setup scripts - tens of SQL scripts that creates 
tables, views, complex triggers, grants permissions and such and finally 
populates database with some pre-data.

So how I should proceed with unit testing with database like that, since some 
operations rely heavily that there really exists all that trigger-function mess 
in the database? So that I don't need everytime to start from the scratch but 
from some known state of the db?

-- 

Jani Tiainen

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Raise field error in models clean method

2013-05-20 Thread Jani Tiainen
On Sun, 19 May 2013 06:38:50 -0700 (PDT)
Kai Schlamp  wrote:

> Hello.
> 
> How to raise a `ValidationException` in the models `clean` method?
> 
> def clean(self):
> from django.core.exceptions import ValidationError
> raise ValidationError({'title': 'not ok'})
> 
> The above does not add the error to the `title` field (when using a form), 
> but to the non field errors.
> 
> This is possible inside a form (`self._errors['title'] = 
> self.error_class([msg])`), but `self._errors` does not exist inside the 
> models `clean` method.
> 
> I know that clean normally is for non field errors, but there are cases 
> when only some kind of combination of values in separate fields are valid. 
> I want to directly associate the error with a field and let the user know 
> "if you change this field than everything passes".
> 
> Is it possible (even if not recommended)?

Well if you consider that error you describe is about combination of fields A 
and B how you can tell that which one is really incorrect? A or B? In most 
cases it's really impossible to tell the difference hence it's more natural to 
report that field combination didn't validated and some action must be done to 
correct the situation. 

So in example case end user has to change field A or field B or even both. 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django & Oracle connection problem

2013-05-16 Thread Jani Tiainen
If you want just to connect Oracle but not run server locally using instant 
client is much more easier option to setup.

On Wed, 15 May 2013 02:43:36 -0700 (PDT)
Michael Van  wrote:

> I have the same error when python managment runserver  :
> cx_Oracle.DatabaseError: ORA-28547: connection to server failed, probable 
> Oracle Net admin error
> and this Error infomation is the same when I type sqlplus try to login.
> My os is Xubuntu13.10, and I installed oracle-instance on ubuntu, 
> so I think that the instance is somewhere error, but I don't konw where it 
> is.
> >_<
> 在 2013年1月25日星期五UTC+8上午6时27分22秒,Dylan Klomparens写道:
> >
> > I have a Django program that is connecting to an Oracle database. In my 
> > settings.py file I have this configuration:
> >
> > DATABASES = {
> >   'default': {
> > 'ENGINE': 'django.db.backends.oracle',
> > 'NAME': 'xe',
> > 'USER': 'MY_USER_NAME',
> > 'PASSWORD': 'abcdefghijklmnopqrstuvwxyz',
> > 'HOST': 'db_server.example.com',
> > 'PORT': '1234',
> >   }}
> >
> > I received a strange error when attempting to load the website:
> >
> > ORA-28547: connection to server failed, probable Oracle Net admin error
> >
> > After further investigation, I sniffed the TCP traffic between the 
> > webserver and the database server. I discovered this text in the network 
> > communication, which I reformatted for this post:
> >
> > (DESCRIPTION=
> > (ADDRESS=
> > (PROTOCOL=TCP)
> > (HOST=1.2.3.4)
> > (PORT=1234)
> > )
> > (CONNECT_DATA=
> > (SID=xe)
> > (CID=
> > (PROGRAM=httpd@webserver_hostname)
> > (HOST=webserver_hostname)
> > (USER=apache)
> > )
> > ))
> >
> > So my question is: why is Django attempting to connect to the Oracle 
> > database with different credentials than the ones I specified? Notably, it 
> > is attempting to use user 'apache' instead of 'MY_USER_NAME'. The database 
> > host IP, port, and SID are correct and what I specified. It just appears to 
> > be the user name that is different.
> >
> > (As a side note, I suppose the password is transmitted separately in a 
> > later portion of the log in process?)
> >
> 
> -- 
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Oracle database TextField limitations and Django admin interface queries

2013-04-10 Thread Jani Tiainen

10.4.2013 14:45, Lauri Savolainen kirjoitti:

A little background: my application is used to manage observational data
which is collected from designated routes annually. Each route object
has a set of observation events which in turn have a date field. The
data is managed by using a (terrible) customized Django admin interface.

In the admin interface list view it's possible to search routes using a
custom search box which just injects parameters like ?route_no=1234 and
so forth into the url resulting in a filtered list view. For the most
part this works but when I want to search for routes that, for example,
have observation events past certain date with a query like
?observationevent__observation_date__gte=2010-01-01 (supposed to show
all routes that have been observed this decade) it raises an
DatabaseError: ORA-00932: inconsistent datatypes: expected - got
NCLOB-exception while using an Oracle database in production. The query
seems to work when using a development SQLite database or doing a query
like
Route.objects.filter(observationevent__observation_date__gte='2012-01-01')
directly in the management console even when using the Oracle production
database.

According to the general notes on databases the Oracle backend has
limitations with TextField-related queries
(https://docs.djangoproject.com/en/dev/ref/databases/#textfield-limitations)
and this seems to be causing this as far as I can tell. As the queries
are created by Django admin I have no idea how I should proceed from
here. Is there some kind of easy way to prevent this from happening on
Oracle or should I implement some kind of manual search function?

I am currently using the following versions:
Django==1.4.5
cx-Oracle==5.1.2
gunicorn==0.17.2
virtualenv==1.5.1



Welcome to among us very few and brave to use Oracle... ;)

What comes to your problem few details are missing but:

Length of the field in model definition and what column type is in the 
database. Also it would be helpful to know are you using legacy database?


Actual error is slightly problematic since it doesn't directly tell what 
is wrong. It's related types of bind variables and any of them might be 
incorrect for some reason.


--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Packaging django, python and a project for one click setup on a windows machine

2013-04-05 Thread Jani Tiainen

5.4.2013 11:44, R R kirjoitti:

Hi,

is there a way to package Python, Django and a Django Project which will
enable the user to set it up with just one click? What i'm intending to
do is to send it to couple of people who will set it up on their windows
machines and then click on a desktop icon which will run the runserver
command and open the localhost URL in the browser. The end users are not
computer-savvy, and also security is not an issue here.


Short answer - "you can't".

Well that is not entirely true but requires quite a bunch of work and 
depends greatly what kind of 3rd party libs your project uses.


Keyword here is cx_Freeze [1] or py2exe [2]. If you're lucky it might 
work with little effort but if everything else fails you can always do 
it by creating special script to gather all the required parts.


See also 
<http://misunderstandings.wordpress.com/2008/06/26/django-desktop-app/>


[1] http://cx-freeze.sourceforge.net/
[2] http://www.py2exe.org/

--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Restful User Authentication for Ember/Backbone client with Tastypie

2013-03-12 Thread Jani Tiainen

10.3.2013 22:54, Pratik Mandrekar kirjoitti:

Hello,

I'm trying to figure out what would be the best way to integrate django
with ember.js/backbone from the user authentication point of view. I'm
using Tastypie for creating RESTful resources.

I have no problem creating APIs once a user has been authenticated using
the Session based authentication but I am wondering what is the best
RESTful way to create  a user authentication API that can confirm to
Session based authentication.

Also if I'm not mistaken the right way to authenticate the client is via
the API key authentication right?


There is not exactly "RESTful way to authenticate", since after all REST 
is just an architecture to represent different resources and thus it's 
totally agnostic what comes to authentications and such.


Simplest one (if you're use HTTP(S)) is to use basic/digest auth. Though 
true REST is protocol agnostic (for example it could use unix sockets)


Query authencation, a.k.a. API key, only one that you can do protocol 
agnostic way.


Cookie-based, for example posting credential query as POST (to create 
new cookie) to /sessions/ url. Binds REST to HTTP(S) protocol again and 
DELETE to /sessions// to logout


Personally, if working with Django and HTTP I would go for cookie based 
auth since it would be natural.


Otherwise API key isn't that bad option.

--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Best ways and common practices to lock the Database before a new deploy

2013-02-21 Thread Jani Tiainen

21.2.2013 18:02, Santiago Basulto kirjoitti:

Hello guys,

we've our app that's working awesome. We do a new release each week.
We've set up a nice deployment process using fabric and everything
works great.

The problem is that, as the application grows, it takes some time to
perform the deploy. And we're using South, so sometimes we need to
migrate some big tables.

So, the questions are:

* How should I lock my DB in the moment of the deployment? Should I
use different DB users at that moment?

* What other strategies do you use at the moment of the deployment you
can recommend?

Thank you very much!



You can't "lock" your database in that sense.

Simplest thing and what you usually do is to just bloock all unwanted 
access to your database like shutdown all running deployments for a 
upgrade period.


For downtime period you can setup static page to state that "maintenance 
in progress" or some other meanful information.


--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: session is not expiring

2013-02-21 Thread Jani Tiainen
I'm not sure but I think if you have background processes on and running 
in Chrome it doesn't actually ever close browser.


Excerpt from 
<http://stackoverflow.com/questions/10617954/chrome-doesnt-delete-session-cookies>:


"Under advanced settings I unchecked 'Continue running background apps 
when Google Chrome is closed' and my session cookies started working as 
they should."



21.2.2013 16:15, Aswani Kumar kirjoitti:

i set file based sessions and the sessions are not expiring even after
closing browser. its the issues in chrome but firefox is good. how can i
fix it.

here is my config

MIDDLEWARE_CLASSES = (
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
)


SESSION_ENGINE = 'django.contrib.sessions.backends.file'

SESSION_EXPIRE_AT_BROWSER_CLOSE = True

SESSION_FILE_PATH = os.getenv("HOME") + '/sessions'

INSTALLED_APPS = (
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
..

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Python trademark at risk in Europe: We need your help!

2013-02-15 Thread Jani Tiainen

I'll post this here since this will touch some of us as well:

http://pyfound.blogspot.fi/2013/02/python-trademark-at-risk-in-europe-we.html

And small quote from beginning of that post:

"For anyone who works in a company that has an office in a EU Community 
member state, we need your help.


There is a company in the UK that is trying to trademark the use of the 
term "Python" for all software, services, servers... pretty much 
anything having to do with a computer."




--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: how to password will come in hidden form in django?

2013-02-14 Thread Jani Tiainen

Hi,

You need to specify widget as PasswordInput on a form if you want to 
show asterisks.


Though using 3rd party package is good option - no need to reinvent wheel.

15.2.2013 8:11, Avnesh Shakya kirjoitti:

i have created my Userinfo model for registration, but password is
showing means it's not filling in hidden form so what will i have to do
for it... please help me

class Userinfo(models.Model):
full_name=models.CharField(max_length=30)
username=models.CharField(max_length=20)
email_address=models.CharField(max_length=75)
password=models.CharField(max_length=255)
reenter_password=models.CharField(max_length=255)
area_of_interest=models.CharField(max_length=255)
def _unicode_(self):
return self.full_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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Object composition in django

2013-02-13 Thread Jani Tiainen

Hi,

You're trying to setup one-to-one relationship.

It means that producer.mailing_address does have exactly one unique 
Address entity. Same goes for physical_address.


What you want is really ForeignKey to address which means that you reuse 
addresses to multiple producer.mailing_address.


Then you can omit related names, or like someone suggested use different 
related names for both fields.


13.2.2013 21:25, Ray Hatfield kirjoitti:

Hi,

I have a model which requires two addresses: a mailing address and a
physical address. From an OO perspective it makes sense to have an
Address class and the Producer to have Address instances as properties,
but I can't seem to achieve this in django while still being able to
edit the addresses inline as part of the Producer admin.

I've tried this sort of thing:

class Address( models.Model ):
 street = models.CharField( ... )
 # city state zip, etc.

class Producer( models.Model ):
 mailing_address = models.OneToOneField( Address, related_name='+' )
 physical_address = models.OneToOneField( Address, related_name='+' )

but when I attempt to inline the addresses in the django admin I run
into trouble. I get errors like:

 has no ForeignKey to 

(This error is true, of course. But I was under the apparently erroneous
impression that including related_name='+' would prevent django from
setting up the reverse relationship.)

I realize I could add a foreign key to Address to associate it with a
specific Producer but this feels backwards to me. An Address shouldn't
need to know whether it's for a Producer or some other object. It's just
an address.

I've been banging my head on this for far too long. Advice?

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: One ->Many forms outside admin

2013-02-11 Thread Jani Tiainen

11.2.2013 13:38, alexandre...@gmail.com kirjoitti:

I think taht is for editing a bunch of equal modelsat the same time...

I need to edit a 1-many relationship in the same manner admin does.

thanks

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Inline formsets to be exact is something that you're looking for:

https://docs.djangoproject.com/en/1.4/topics/forms/modelforms/#inline-formsets

--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: One ->Many forms outside admin

2013-02-11 Thread Jani Tiainen

Hi,

I think you're looking for (model) formsets.

11.2.2013 10:49, alexandre...@gmail.com kirjoitti:

Hi

I need to edit

1->many
   ->many  forms on my pages like in admin, using inlines, but outside admin

can anyone give clues on how to do it

Regards
Alex

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Problems doing ajax post with ImageField

2013-02-10 Thread Jani Tiainen

Hi,

There is no way to save files through XHR, (not at least without HTML5 
features).


One quite common approach is to use temporary, hidden iframe where form 
is duplicated along the filefield and then submit that form as normal 
page submit and then to read response one way or another.


I don't know exact procedure how that works in jquery but maybe this 
helps: http://bit.ly/11AA3dW


11.2.2013 0:28, bobhaugen kirjoitti:

Here's the relevant parts of the model:

class Resource(models.Model):
 photo = ThumbnailerImageField(_("photo"),
 upload_to='photos', blank=True, null=True)

This works fine in admin and with regular form posts.

Trying to use jquery.post in one situation to post a photo without
suffering a page reload.

With the regular post, the photo field returns like this (in
form.cleaned_data):
'photo': 

And request.FILES is like this:
]}>

With the jquery post, photo is None and the MultiValueDict is empty.

In both cases the form is set up with enctype="multipart/form-data",
and the form is instantiated in the view with
form = ResourceForm(request.POST, request.FILES)

What am I doing wrong?

Here's the javascript:

$("#detailForm").submit(function(event) {
event.preventDefault();

var $form = $( this ),
url = $form.attr( 'action' );

var formData = $form.serialize();
saveResource(url, formData);

});

function saveResource(url, formData)
{
notifySaving();
var jqxhr = $.post( url, formData,
function( data ) {
$('#detailModal').modal('hide');
notifySaved();
resourceSaved = true;
})
.fail(function()
{
$('#detailModal').modal('hide');
notifyProblem();
resourceSaved = false;
startRetrying();
}
);
}

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Object level permissions implementation

2013-02-06 Thread Jani Tiainen

That's something I had in mind also.

And I think that is quite a best thing to do.

6.2.2013 18:09, bobhaugen kirjoitti:

I'm not sure this is the best way to do it, but for what I think is a
similar situation, I created a template tag and a model instance method.

The template tag asks the model instance method whether the user has
permission.

Here's the template tag:
https://github.com/bhaugen/localecon/blob/master/clusters/templatetags/permissions.py

Here's the instance method:
https://github.com/bhaugen/localecon/blob/master/clusters/models.py#L176

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: plz help me for error in python for django.....

2013-02-06 Thread Jani Tiainen

Django doesn't touch tables that already exists in database.

So if you had model Poll run syncdb and then change, add or remove 
fields Django doesn't modify underlying table.


There is few options that resolves your problem:
- Manually migrate your database using plain SQL.
- Recreate table or whole database.
- Use south for database migrations.

6.2.2013 12:08, Avnesh Shakya kirjoitti:

thanks alot... but i have set it but again it's showing new
error.. like...

C:\mysite>python manage.py shell
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
 >>> from polls.models import Poll,Choice
 >>> Poll.objects.all()
Traceback (most recent call last):
   File "", line 1, in 
   File "C:\Python27\lib\site-packages\django\db\models\query.py", line
72, in __repr__
 data = list(self[:REPR_OUTPUT_SIZE + 1])
   File "C:\Python27\lib\site-packages\django\db\models\query.py", line
87, in __len__
 self._result_cache.extend(self._iter)
   File "C:\Python27\lib\site-packages\django\db\models\query.py", line
291, in iterator
 for row in compiler.results_iter():
   File
"C:\Python27\lib\site-packages\django\db\models\sql\compiler.py", line
763, in results_iter
 for rows in self.execute_sql(MULTI):
   File
"C:\Python27\lib\site-packages\django\db\models\sql\compiler.py", line
818, in execute_sql
 cursor.execute(sql, params)
   File "C:\Python27\lib\site-packages\django\db\backends\util.py", line
40, in execute
 return self.cursor.execute(sql, params)
   File
"C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py", line
344, in execute
 return Database.Cursor.execute(self, query, params)
DatabaseError: no such column: polls_poll.pub_date
 >>>






On Wed, Feb 6, 2013 at 2:49 PM, Jani Tiainen <rede...@gmail.com
<mailto:rede...@gmail.com>> wrote:

Now look your Poll model and try to find field "pub_date" there...

:)

6.2.2013 11:03, Avnesh Shakya kirjoitti:

thanks.. i have added my polls.models file

On Wed, Feb 6, 2013 at 2:20 PM, Sergiy Khohlov
<skhoh...@gmail.com <mailto:skhoh...@gmail.com>
<mailto:skhoh...@gmail.com <mailto:skhoh...@gmail.com>>> wrote:

 1) please provide your model Poll
 2) are you run syncdb ?
 Many thanks,

 Serge


 +380 636150445
 skype: skhohlov


 2013/2/6 Avnesh Shakya <avnesh.n...@gmail.com
<mailto:avnesh.n...@gmail.com>
 <mailto:avnesh.n...@gmail.com
<mailto:avnesh.n...@gmail.com>>__>:

  >
  > Here i want to explore database API but it's generating
 error..
  > C:\mysite>python manage.py shell
  > Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC
v.1500 32 bit
 (Intel)] on
  > win32
  > Type "help", "copyright", "credits" or "license" for more
 information.
  > (InteractiveConsole)
  >>>> from polls.models import Poll,Choice
  >>>> Poll.objects.all()
  > []
  >>>> import django
  >>>> from django.utils import timezone
  >>>> p= Poll(question="what's new?",pub_date= timezone.now())
  > Traceback (most recent call last):
  >   File "", line 1, in 
  >   File
"C:\Python27\lib\site-__packages\django\db\models\__base.py",
 line 367,
  > in __init__
  > raise TypeError("'%s' is an invalid keyword argument
for this
 function"
  > % kwargs.keys()[0])
  > TypeError: 'pub_date' is an invalid keyword argument for
this
 function
  >>>>
  >
  > --
  > You received this message because you are subscribed to the
 Google Groups
  > "Django users" group.
  > To unsubscribe from this group and stop receiving emails
from it,
 send an
  > email to django-users+unsubscribe@__googlegroups.com
<mailto:django-users%2bunsubscr...@googlegroups.com>
 <mailto:django-users%__2bunsubscr...@googlegroups.com
<mailto:django-users%252bunsubscr...@googlegroups.com>__>.

  > To post to this group, send email to
dja

Re: plz help me for error in python for django.....

2013-02-06 Thread Jani Tiainen

Now look your Poll model and try to find field "pub_date" there...

:)

6.2.2013 11:03, Avnesh Shakya kirjoitti:

thanks.. i have added my polls.models file

On Wed, Feb 6, 2013 at 2:20 PM, Sergiy Khohlov <skhoh...@gmail.com
<mailto:skhoh...@gmail.com>> wrote:

1) please provide your model Poll
2) are you run syncdb ?
Many thanks,

Serge


+380 636150445
skype: skhohlov


2013/2/6 Avnesh Shakya <avnesh.n...@gmail.com
<mailto:avnesh.n...@gmail.com>>:
 >
 > Here i want to explore database API but it's generating
error..
 > C:\mysite>python manage.py shell
 > Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit
(Intel)] on
 > win32
 > Type "help", "copyright", "credits" or "license" for more
information.
 > (InteractiveConsole)
 >>>> from polls.models import Poll,Choice
 >>>> Poll.objects.all()
 > []
 >>>> import django
 >>>> from django.utils import timezone
 >>>> p= Poll(question="what's new?",pub_date= timezone.now())
 > Traceback (most recent call last):
 >   File "", line 1, in 
 >   File "C:\Python27\lib\site-packages\django\db\models\base.py",
line 367,
 > in __init__
 > raise TypeError("'%s' is an invalid keyword argument for this
function"
 > % kwargs.keys()[0])
 > TypeError: 'pub_date' is an invalid keyword argument for this
function
 >>>>
 >
 > --
 > 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
<mailto:django-users%2bunsubscr...@googlegroups.com>.
 > To post to this group, send email to
django-users@googlegroups.com <mailto:django-users@googlegroups.com>.
 > Visit this group at
http://groups.google.com/group/django-users?hl=en.
 > For more options, visit https://groups.google.com/groups/opt_out.
 >
 >

--
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
<mailto:django-users%2bunsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Object level permissions implementation

2013-02-05 Thread Jani Tiainen

Actually I had slightly incorrect term:

I need _field_ (column) level permissions, not object (row) level 
permissions.


6.2.2013 8:36, Jani Tiainen kirjoitti:

No it's not, it's more like enhancement to standard Django permissions
that works with predefined "named" permissions.

But I need to actually look data of instance and using that to check
does user have permission to access instance.

Let's make this slightly simpler:

I have a plan model:

class Plan(models.Model):
 name = models.TextField(max_length=200)

and I've Entity model:

class Entity(models.Model):
 name = models.TextField(max_length=200, unique=True)
 plan = models.ForeignKey(Plan, null=True, blank=True)
 is_public = models.BooleanField(default=True)

 location = models.PolygonField(srid=4326)

now I have user A that has access to entities belonging to plans named
"foo" and "bar" that are inside user working area (location is within
some polygon) and all entities that are marked as public.

So I need to construct query that is something like this to get queryset
containing only objects that user has permission to:

Entity.objects.filter(
 Q(Q(plan__name__in=user.allowed_plans.all() &
   Q(location__within=user.working_area)) | Q(is_public=True)
)

It would be simple if all attributes would be on model only but some of
my real models are really complex and needs to go quite deep in the
relations to find out does user has access to object or not.

That's why I would actually use standard django authorization mechanism
and there always delegate checking to model instance that can tell does
user have permission or not to access this object.

5.2.2013 21:00, Nikolas Stevenson-Molnar kirjoitti:

If I understand correctly, that's exactly what it's for:
https://code.osuosl.org/projects/object-permissions/wiki/Using#Checking-Perms


_Nik

On 2/4/2013 10:17 PM, Jani Tiainen wrote:

Afaik object-permission works reverse what I need - it adds spesific
permissions to groups/users to single object. But I need to check
(mostly through foreign keys and/or spatial relation) does user has
permission to see that data or not.








--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Object level permissions implementation

2013-02-05 Thread Jani Tiainen
No it's not, it's more like enhancement to standard Django permissions 
that works with predefined "named" permissions.


But I need to actually look data of instance and using that to check 
does user have permission to access instance.


Let's make this slightly simpler:

I have a plan model:

class Plan(models.Model):
name = models.TextField(max_length=200)

and I've Entity model:

class Entity(models.Model):
name = models.TextField(max_length=200, unique=True)
plan = models.ForeignKey(Plan, null=True, blank=True)
is_public = models.BooleanField(default=True)

location = models.PolygonField(srid=4326)

now I have user A that has access to entities belonging to plans named 
"foo" and "bar" that are inside user working area (location is within 
some polygon) and all entities that are marked as public.


So I need to construct query that is something like this to get queryset 
containing only objects that user has permission to:


Entity.objects.filter(
Q(Q(plan__name__in=user.allowed_plans.all() &
  Q(location__within=user.working_area)) | Q(is_public=True)
)

It would be simple if all attributes would be on model only but some of 
my real models are really complex and needs to go quite deep in the 
relations to find out does user has access to object or not.


That's why I would actually use standard django authorization mechanism 
and there always delegate checking to model instance that can tell does 
user have permission or not to access this object.


5.2.2013 21:00, Nikolas Stevenson-Molnar kirjoitti:

If I understand correctly, that's exactly what it's for:
https://code.osuosl.org/projects/object-permissions/wiki/Using#Checking-Perms

_Nik

On 2/4/2013 10:17 PM, Jani Tiainen wrote:

Afaik object-permission works reverse what I need - it adds spesific
permissions to groups/users to single object. But I need to check
(mostly through foreign keys and/or spatial relation) does user has
permission to see that data or not.





--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Object level permissions implementation

2013-02-04 Thread Jani Tiainen
Yes, I've (a long time ago though so package may be much better now) but 
it doesn't give exactly what I need.


Afaik object-permission works reverse what I need - it adds spesific 
permissions to groups/users to single object. But I need to check 
(mostly through foreign keys and/or spatial relation) does user has 
permission to see that data or not.


And my bad, I forgot to add Key fk lock nulls true.

So datamodel is like this:
Building contains zero or more Apartments.
Door can belong to building or apartment.
Lock belongs to door.
Key belongs to owner and may belong to specific lock.

So that in mind I need to restrict data fetching according to rules like:

User X has access (key type 'PUBLIC') to locks in buildings starting 
with letter 'A' and only doors of types 'CARAGE' or 'ENTRANCE'.



5.2.2013 5:53, Nikolas Stevenson-Molnar kirjoitti:

Have you had a look at this 3rd-party package?
http://pypi.python.org/pypi/django-object-permissions

_Nik

On 2/4/2013 4:59 AM, Jani Tiainen wrote:

Hi all,

I've in need of implementing (rather complex) object level permissions.

I've difficulties to determine how to proceed.

Let's assume that I've following models:

class Building(...):
 name = models.TextField(max_length=100)

class Apartment(...):
 name = models.TextField(max_length=100)
 building = models.ForeignKey(Building)

class Door(...):
 DOOR_TYPES =
 (('CARAGE', 'Carage'),
  ('ENTRANCE', 'Entrance'),
  ('PRIVATE', 'Private'))

 door_type = models.TextField(max_length=100, choices=DOOR_TYPES)
 name = models.TextField(max_length=100)
 building = models.ForeignKey(Building)
 apartment = models.ForeignKey(Apartment, null=True, blank=True)

class Lock(...):
 door = models.ForeignKey(Door)

class Key(...):
 KEY_TYPES =
 (('ALL_ACCESS', 'All access'),
  ('PRIVATE', 'Private'),
  ('PUBLIC', 'Public'))

 key_type = models.TextField(max_length=100, choices=KEY_TYPES)
 owner = models.ForeignKey(User)
 lock = models.ForeignKey(Lock)


Now each user will have access to doors according their key:
Also user may have limited "public" key that allows access to public
places like CARAGE or ENTRANCE door.

Or like postman would have access to Entrance door only but not to
carage nor private doors (apartments).

So far I've figured out following ways to do what I'm looking for:
1) I could implement all rules to authentication backend.
2) Delegate actual permission checking to models.
3) Something else and better.






--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Object level permissions implementation

2013-02-04 Thread Jani Tiainen

Hi all,

I've in need of implementing (rather complex) object level permissions.

I've difficulties to determine how to proceed.

Let's assume that I've following models:

class Building(...):
name = models.TextField(max_length=100)

class Apartment(...):
name = models.TextField(max_length=100)
building = models.ForeignKey(Building)

class Door(...):
DOOR_TYPES =
(('CARAGE', 'Carage'),
 ('ENTRANCE', 'Entrance'),
 ('PRIVATE', 'Private'))

door_type = models.TextField(max_length=100, choices=DOOR_TYPES)
name = models.TextField(max_length=100)
building = models.ForeignKey(Building)
apartment = models.ForeignKey(Apartment, null=True, blank=True)

class Lock(...):
door = models.ForeignKey(Door)

class Key(...):
KEY_TYPES =
(('ALL_ACCESS', 'All access'),
 ('PRIVATE', 'Private'),
 ('PUBLIC', 'Public'))

key_type = models.TextField(max_length=100, choices=KEY_TYPES)
owner = models.ForeignKey(User)
lock = models.ForeignKey(Lock)


Now each user will have access to doors according their key:
Also user may have limited "public" key that allows access to public 
places like CARAGE or ENTRANCE door.


Or like postman would have access to Entrance door only but not to 
carage nor private doors (apartments).


So far I've figured out following ways to do what I'm looking for:
1) I could implement all rules to authentication backend.
2) Delegate actual permission checking to models.
3) Something else and better.

--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Struggling with slow startup / SQL in new app (using raw SQL)

2013-01-22 Thread Jani Tiainen

Hi,

I see that you had quite a bunch of m2m keys.

Have you tried recent version of Django (1.4+) with prefetch_related() [1] ?


[1] 
<https://docs.djangoproject.com/en/1.4/ref/models/querysets/#prefetch-related>



22.1.2013 13:57, Matt Andrews kirjoitti:

Hi Jani,

I made a StackOverflow post last year with an example of the ORM stuff I
tried and the poor queries it produced:
http://stackoverflow.com/questions/5843457/django-objects-all-making-360-queries-how-can-i-optimise-this-manytomany

There's also this discussion about how using the same queryset in two
places in the template caused Django to request its data twice:
http://stackoverflow.com/questions/9447053/best-way-to-slice-a-django-queryset-without-hitting-the-database-more-than-once
 (this
was easily fixed, but again, not very intuitive and frustrated me)

I don't have the data to hand currently but I also remember seeing weird
things happen where queries would end with stuff like "... LIMIT
234423445" (or some crazy number which I'd never entered and was orders
of magnitude bigger than the number of rows in the table).

I'm aware these are probably edge cases that are down to my own novice
status, but even using things like select_related(), it wasn't doing
what I wanted. I just felt it easier to use my existing SQL (I'm
converting a PHP app over to Django) and I'm not concerned about
database portability (switching to postgres or whatever).

Nik: just realised I missed your final question. For the SQL posted
above, the numbers are approximately: 12,000 rows in the `news` table,
maybe 10 `news_category` rows, about 100 `writers` and around 3000
`images`. All properly indexed and with sensible column types.

On Tuesday, January 22, 2013 10:53:40 AM UTC, Jani Tiainen wrote:

Hi,

  From your raw SQL I saw you're doing few joins. So I suppose you do
quite a few foreign key fetches.

You didn't mention anything how you originally tried to solve case with
ORM. Could you please publish what you had when things were slow?

22.1.2013 12:26, Matt Andrews kirjoitti:
 > Hi Nik,
 >
 > Thanks - I do feel like by circumventing the ORM I've just "given
up"
 > and perhaps I'll reconsider -- none of my queries are particularly
 > "specialist" (as the sample above indicates) - I just found Django
 > generating odd things.
 >
 > To answer your questions:
 >
 > 1. Yes, reloading the page sees the same time for the queries (it
just
 > feels as though the entire process takes a second or two to
start, which
 > is perhaps not related to SQL itself).
 >
 > 2. I believe so, yes (it's shared hosting...).
 >
 > If you're curious, you can see a sample of the app at
 > http://beta.scenepointblank.com <http://beta.scenepointblank.com>
(obviously you won't see the SQL, but
 > the "delay" between pages, even though these pages are all cached
for
 > 2hrs+, is partly my concern here).
 >
 > On Tuesday, January 22, 2013 4:24:09 AM UTC, Nikolas
Stevenson-Molnar wrote:
 >
 > Hi Matt,
 >
 > Firstly, I encourage you to have another crack a the ORM. It can
 > certainly seem a bit aggravating at times if you're coming
from a
 > SQL mindset, but really pays off down the road in terms of
 > maintainability and readability. Typically you should only
need raw
 > queries in Django in cases where you have super-specialized
(that
 > uses views or non-standard functions) queries or need some
specific
 > optimization. If there's really no way to perform many of your
 > "day-to-day" queries with the ORM then that's an indication
that a
 > different database design may fit your data model better. I
 > understand that you may have a unique situation, but I just
wanted
 > to throw that out there as I personally find the ORM to be a
huge
 > time saver.
 >
 > Now, with that out of the way... a couple of considerations:
1) you
 > say it's a slow "startup"; if you refresh the page do the
queries
 > run just as slow the second time around? and 2) are your
Django app
 > and phpMyAdmin running on the same machine? If not, could
transit
 > time be an issue?
 >
 > Finally, can you give an idea about the size of the tables in
 > question? How many rows in each?
 >
 > _Nik
 >
 > On 1/21/2013 3:25 PM, Matt Andrews wrote:
 >> Hi all,
 >>
 >> Fairly new to Django. I ended up pulling out all of the
 >> ORM-generated queries and writing my own S

Re: Struggling with slow startup / SQL in new app (using raw SQL)

2013-01-22 Thread Jani Tiainen

Hi,

From your raw SQL I saw you're doing few joins. So I suppose you do 
quite a few foreign key fetches.


You didn't mention anything how you originally tried to solve case with 
ORM. Could you please publish what you had when things were slow?


22.1.2013 12:26, Matt Andrews kirjoitti:

Hi Nik,

Thanks - I do feel like by circumventing the ORM I've just "given up"
and perhaps I'll reconsider -- none of my queries are particularly
"specialist" (as the sample above indicates) - I just found Django
generating odd things.

To answer your questions:

1. Yes, reloading the page sees the same time for the queries (it just
feels as though the entire process takes a second or two to start, which
is perhaps not related to SQL itself).

2. I believe so, yes (it's shared hosting...).

If you're curious, you can see a sample of the app at
http://beta.scenepointblank.com (obviously you won't see the SQL, but
the "delay" between pages, even though these pages are all cached for
2hrs+, is partly my concern here).

On Tuesday, January 22, 2013 4:24:09 AM UTC, Nikolas Stevenson-Molnar wrote:

Hi Matt,

Firstly, I encourage you to have another crack a the ORM. It can
certainly seem a bit aggravating at times if you're coming from a
SQL mindset, but really pays off down the road in terms of
maintainability and readability. Typically you should only need raw
queries in Django in cases where you have super-specialized (that
uses views or non-standard functions) queries or need some specific
optimization. If there's really no way to perform many of your
"day-to-day" queries with the ORM then that's an indication that a
different database design may fit your data model better. I
understand that you may have a unique situation, but I just wanted
to throw that out there as I personally find the ORM to be a huge
time saver.

Now, with that out of the way... a couple of considerations: 1) you
say it's a slow "startup"; if you refresh the page do the queries
run just as slow the second time around? and 2) are your Django app
and phpMyAdmin running on the same machine? If not, could transit
time be an issue?

Finally, can you give an idea about the size of the tables in
question? How many rows in each?

_Nik

On 1/21/2013 3:25 PM, Matt Andrews wrote:

Hi all,

Fairly new to Django. I ended up pulling out all of the
ORM-generated queries and writing my own SQL directly (I got fed
up trying to work out how to achieve the kind of things I needed
without Django adding in extra joins or unintended WHERE clauses
etc). All my app's SQL uses cursor.execute() and the
dictfetchall() method as referenced here

<https://docs.djangoproject.com/en/dev/topics/db/sql/#django.db.models.Manager.raw>.


I've found that my app incurs a couple of seconds load time in
production, with CPU time at 2532ms and overall time 4684ms
(according to the debug toolbar). I'm seeing 8 SQL queries take
380ms, and each one seems to be several times slower when made by
Django versus hitting the database through phpMyAdmin or
something: eg, this query:

SELECT * FROM news
JOIN news_categories ON news.news_category_id =
news_categories.id <http://news_categories.id>
LEFT JOIN writers ON news.writer_id = writers.id
<http://writers.id>
LEFT JOIN images ON news.image_id = images.id <http://images.id>
ORDER BY news.is_sticky DESC, news.date_posted DESC
LIMIT 10


This takes 14.8ms when run in phpMyAdmin (against the production
database) but Django reports it as 85.2ms. The same ratios are
true for all my other queries.

All I can think of is the note on the dictfetchall() method in the
Django docs which describes a "small performance hit". Is this it?!

I've profiled the app too, although I'm a bit hazy about what it
all means. Here's a dump of the result:
http://pastebin.com/raw.php?i=UHE9edVC
<http://pastebin.com/raw.php?i=UHE9edVC> (this is from running on
my local server rather than production but performance is broadly
similar).

Can anyone help me? I realise I've perhaps gone off-piste by
writing raw SQL but I feel it was justified.

thanks,
Matt



--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Global filtering of the querystes

2013-01-21 Thread Jani Tiainen

Hi,

I've several models that share same attribute and form doing ajax 
queries to/from form in a browser window.


For example owner:

class MyClass(models.Model):
title = models.TextField(max_length=100)
owner = models.TextField(max_length=100)

class MyOtherClass(models.Model):
title = models.TextField(max_length=100)
value = models.IntegerField()
owner = models.TextField(max_length=100)

And so on.

Now I would like to user have option in browser to filter any query 
based on model that has "owner" property to be filtered by owner.


What is the best way to doit?

I only could come up with threadlocals and special manager that can be 
fed with global filtering rules.


--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ORM, Oracle and UTF-8 encoding problem.

2013-01-10 Thread Jani Tiainen

10.1.2013 8:59, Ian Kelly kirjoitti:

On Wed, Jan 9, 2013 at 11:40 PM, Jani Tiainen <rede...@gmail.com> wrote:

If we just force using force_unicode everything works except in older
versions of cx_Oracle (our server had 5.0.4 or something) connection strings
can't be unicode for some reason.


Sure, that's why the check exists in the first place.  Prior to 5.1
cx_Oracle could be built either with Unicode or without.  If the
former, it would accept only unicode strings and would raise an
exception on byte strings.  If the latter, it would be exactly the
opposite.

Does it work for you using force_bytes with 5.0.4?



That's on my production server that runs 1.3.x version. smart_str (which 
detection selects) does not work.


using force_unicode works (except for connection string).

Also depending on what OCI client 10.2.0.5 or instant client 11.2 is 
used when compiling cx_Oracle causes variation. 10.2.0.5 doesn't work 
with smart_str while 11.2 does work.


Both can take plain unicode (u'') when using 
just cx_Oracle commands without any problems.


Note:

If I add manually some unicode to database Django can read it without 
any problems.


--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



<    1   2   3   4   5   6   7   8   >