function to create objects in a given model

2014-05-20 Thread Chansons
Hello everybody,

I'm new to django, and writing my first app, I have a question before 
deploying it.

I need to have a function that would create or modify, according to a few 
rules and a precise instance of a model (Song), many instances of another 
model (Words) at once. 
Writing that function is easy, my problem is, where should I put it, so 
it's easy to use when the application will be in production? 
Should it be in the model layer? Or in a separate module? Will I call it 
with the shell? Is it possible to access it via the admin site? Or any 
other way?

I don't find anything about that in the docs, or in google, any ideas will 
be welcome. I can be more precise if needed...
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/81d42f98-04da-4e8f-8c0b-3ac86601e116%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: function to create objects in a given model

2014-05-20 Thread Venkatraman S
On Tue, May 20, 2014 at 8:39 PM, Chansons  wrote:

> Hello everybody,
>
> I'm new to django, and writing my first app, I have a question before
> deploying it.
>
> I need to have a function that would create or modify, according to a few
> rules and a precise instance of a model (Song), many instances of another
> model (Words) at once.
> Writing that function is easy, my problem is, where should I put it, so
> it's easy to use when the application will be in production?
> Should it be in the model layer? Or in a separate module? Will I call it
> with the shell? Is it possible to access it via the admin site? Or any
> other way?
>
>
https://docs.djangoproject.com/en/dev/howto/initial-data/

-V

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


Re: M2M frustration

2014-05-20 Thread Joris


Hi Russell,


Very interesting, now everything makes sense.
And thank you for the suggested solution, we tried it today and it works 
now, no more random import hell.

Looking forward to Django 1.7.

Best
Joris



op 19-05-14 06:00, Russell Keith-Magee schreef:

Hi Joris,

It's an edge case, but there are a small number of circumstances where 
it is possible to get different behaviour in the development server vs 
Apache/production. The problems usually stem from import side effects, 
especially those caused by circular references in imports.


The reason these bugs manifest is that the startup sequence for Django 
(pre 1.7) isn't strictly controlled. In development, there is a 
predictable startup order -- the validate management command is 
executed as part of starting the development server, and this validate 
step does a predictable import of all models modules. However, in 
production, validate isn't run (after all, it shouldn't be needed); so 
the way certain references are resolved is affected by the way that 
the first queries are issued. It is therefore theoretically possible 
to end up with subtle differences in FK and M2M resolution between 
development and production.


The immediate fix - put a manual call to the validate management 
command in your WSGI file. This will add a slight startup overhead to 
the first request, but will result in a predictable startup order. 
Graham Dumpleton explains how (and some of the why) in this blog post:


http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

(The other solution is to simplify your module structure so that the 
problem circular references don't exist - but it's a lot harder to 
point at a simple fix. Over the years, we've spent a lot of time 
resolving issues with model references, and we've fixed all the 
problems we're aware of… but it's the nature of edge cases to be hard 
to track down)


The good news is that in Django 1.7 (soon to be released), this sort 
of bug shouldn't happen. Django 1.7 has a predictable startup order, 
regardless of whether you're in production or development.


I hope this helps.

Yours,
Russ Magee %-)

On Mon, May 19, 2014 at 2:56 AM, Joris > wrote:



Dear Mark,

Thanks for your suggestion.

Yes, more or less, I've been playing with the order but the models
are so complex with lots of overrides and many fields that it's
hard to keep track. Also the Python/Django backtrace is useless here.

I just find it so curious that all of this doesn't happen on the
Python debugging webserver...

Joris




op 18-05-14 21:41, Mark Phillips schreef:


Jorris,

Have you tried changing the order of imports in your model? From
a quick read of the references, that helped some folks.

Mark

On May 17, 2014 9:24 AM, "Joris" mailto:jmailli...@promani.be>> wrote:

Dear all, please help me with this unsolved mystery.

Error: "Cannot resolve keyword u'' into
field. Choices are: "


1) Error in admin
In the admin it only happens when DEBUG=True. Works perfectly
when DEBUG=False.
The error occurs when opening the form view of the model that
has the M2M field.

2) In code
Here the error is also present when DEBUG=False.
The error occurs when accessing the model field, field, for
example self.my_m2m_field.all()


The error doesn't happen locally on the Django/Python debug
server. On the testing server, which is Apache2 + wsgi, it
does occur. The versions of Python  (2.7) and Django (1.5.7)
are the same on both computers.
The result is that a fellow developer is accusing me of being
neglective with testing the code before uploading it :-(

There have been people with similar problems, but it has
never been solved:
https://groups.google.com/forum/#!topic/django-users/E4UVZHf6kP8


http://stackoverflow.com/questions/19145787/fielderror-cannot-resolve-keyword--into-field

http://chase-seibert.github.io/blog/2010/04/30/django-manytomany-error-cannot-resolve-keyword-xxx-into-a-field.html
http://code.djangoproject.com/ticket/1796 (7 year old django
bug which is reported fixed but in fact is not)


So it seems to be a bug deep down in Django.
This makes the use of M2M fields impossible for my
application, which is quite a problem.

Instead of trying to find the bug in Django, would anyone
have any clue why it does work on the Python debug server and
not on Apache2?


Thank you!
J

-- 
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

BookMarker Project - Opening local files on localhost through Django generated pages

2014-05-20 Thread Aseem Bansal
I am working on a BookMarker project for managing my bookmarks. I was 
creating the search page for lisitng bookmarks as per categories. I hit a 
snag while testing it. I am unable to open locally stored webpages. I 
understand that it is for security purposes but is it possible 
(cross-browser way) to grant permissions for a app to open locally stored 
files? The app can ask for permissions for 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/f6aec47e-8dd9-42c5-a9bd-9f7e32395787%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: BookMarker Project - Opening local files on localhost through Django generated pages

2014-05-20 Thread Adam Stein
On Tue, 2014-05-20 at 11:29 -0700, Aseem Bansal wrote:
> I am working on a BookMarker project for managing my bookmarks. I was
> creating the search page for lisitng bookmarks as per categories. I
> hit a snag while testing it. I am unable to open locally stored
> webpages. I understand that it is for security purposes but is it
> possible (cross-browser way) to grant permissions for a app to open
> locally stored files? The app can ask for permissions for this.

Are you running with DEBUG=True or did you set ALLOWED_HOSTS?


-- 
Adam (a...@csh.rit.edu)

-- 
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/1400611202.13850.26.camel%40zookeeper.steinhome.net.
For more options, visit https://groups.google.com/d/optout.


What happens when secret key is lost?

2014-05-20 Thread Henning Sprang
Hi,

I developed quite a bit in Django already, but only now I am the first
time responsible for putting something into real production use.

So I work through the deployment checklist, and it says the secret key
must be kept super secret. One example shows how to set it as
environment variable.

The question is, what happens when I lose it - when it's used for
password hash salt, doesn't that mean if it's lost, all users have to
reset their password, don't they?

Also, if it should be kept secret, I guess it's safe to assume that
using an online generator like
https://djskgen.herokuapp.com/ is not the smartest idea one can come
up with, right?

Cheers and thanks in advance,
Henning

-- 
Henning Sprang
http://www.sprang.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/CAB10%2BLttXyVO8NRJ3S4jG82_c_cOK2po9EoQmRj1hbOA029q7Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: function to create objects in a given model

2014-05-20 Thread Chansons
Hello,

thanks for your answer, I knew about fixtures, but I'm not sure it's really 
adapted to what I need.

Adding or modifying those instances of a model will depend on a precise 
instance of another model: when I create a song, I also want to find in the 
existing glossary / or add the words of the song. I will have to do that 
often, each time I add a new song. 
If I use fixture, I would have to modify or create the instances 'outside' 
the application, and use loaddata afterwards. 

Isn't there an easier, more direct way to do this? Or perhaps, I didn't 
quite understand what you meant by that?

 



Le mardi 20 mai 2014 17:32:19 UTC+2, Venkatraman.S. a écrit :
>
>
> https://docs.djangoproject.com/en/dev/howto/initial-data/
>
> -V 
>

-- 
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/ffcb89bd-74a4-410b-b886-884c1cb920c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: function to create objects in a given model

2014-05-20 Thread Ilya Kazakevich
Hello, 

Try managers: https://docs.djangoproject.com/en/1.6/topics/db/managers/

Ilya Kazakevich,
JetBrains PyCharm (Best Python/Django IDE)
http://www.jetbrains.com/pycharm/
"Develop with pleasure!"


>-Original Message-
>From: django-users@googlegroups.com
>[mailto:django-users@googlegroups.com] On Behalf Of Chansons
>Sent: Tuesday, May 20, 2014 7:10 PM
>To: django-users@googlegroups.com
>Subject: function to create objects in a given model
>
>Hello everybody,
>
>I'm new to django, and writing my first app, I have a question before 
>deploying it.
>
>I need to have a function that would create or modify, according to a few rules
>and a precise instance of a model (Song), many instances of another model
>(Words) at once.
>Writing that function is easy, my problem is, where should I put it, so it's 
>easy to
>use when the application will be in production?
>Should it be in the model layer? Or in a separate module? Will I call it with 
>the
>shell? Is it possible to access it via the admin site? Or any other way?
>
>I don't find anything about that in the docs, or in google, any ideas will be
>welcome. I can be more precise if needed...
>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/81d42f98-04da-4e8f-8c0b-3ac
>86601e116%40googlegroups.com
>c86601e116%40googlegroups.com?utm_medium=email&utm_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/08b401cf745c%246253b520%2426fb1f60%24%40JetBrains.com.
For more options, visit https://groups.google.com/d/optout.


Re: What happens when secret key is lost?

2014-05-20 Thread Erik Romijn
Hello Henning,

On 20 May 2014, at 20:40, Henning Sprang  wrote:
> The question is, what happens when I lose it - when it's used for
> password hash salt, doesn't that mean if it's lost, all users have to
> reset their password, don't they?

If it were used for that, that would indeed be the scenario. Fortunately, it's 
not.

There is a current ticket open on documenting exactly this question: 
https://code.djangoproject.com/ticket/22310. I'd worked through most of it but 
somehow lost my changes.

>From memory, and without review by a second pair of eyes, I believe the 
>effects are limited to:
- All currently existing sessions are invalidated.
- All password reset tokens are invalidated.
- All form previews in progress require an additional confirmation.
- All form wizards in progress are reset, and if using the cookie backend for 
form wizards, this may lead to exceptions.

Also, any third party packages or any of your own code that uses the secret key 
may be affected. Notably not affected (in Django itself) are user passwords, 
and general content in the database.

> Also, if it should be kept secret, I guess it's safe to assume that
> using an online generator like
> https://djskgen.herokuapp.com/ is not the smartest idea one can come
> up with, right?

I would not recommend using such a service. Although it's probably not 
malicious, there is no reason to use this either. Remember also that the secret 
key has no particular format. Any random string, e.g. one that you may get from 
a password manager, can be used.

And yes, it is very important to keep it secret. The worst case scenario for 
secret key leakage, in particular configurations, is arbitrary remote code 
execution.

cheers,
Erik

-- 
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/85EEF3AC-9BEB-41F8-AD31-C6BF3D3FFFD7%40solidlinks.nl.
For more options, visit https://groups.google.com/d/optout.


Re: What happens when secret key is lost?

2014-05-20 Thread Tim Chase
On 2014-05-20 21:34, Erik Romijn wrote:
> > The question is, what happens when I lose it - when it's used for
> > password hash salt, doesn't that mean if it's lost, all users
> > have to reset their password, don't they?  
> 
> If it were used for that, that would indeed be the scenario.
> Fortunately, it's not.
> 
> There is a current ticket open on documenting exactly this
> question: https://code.djangoproject.com/ticket/22310. I'd worked
> through most of it but somehow lost my changes.
> 
> From memory, and without review by a second pair of eyes, I believe
> the effects are limited to:
> - All currently existing sessions are invalidated.
> - All password reset tokens are invalidated.
> - All form previews in progress require an additional confirmation.
> - All form wizards in progress are reset, and if using the cookie
> backend for form wizards, this may lead to exceptions.
> 
> Also, any third party packages or any of your own code that uses
> the secret key may be affected. Notably not affected (in Django
> itself) are user passwords, and general content in the database.

Thanks for the concise summary.  I've researched this on my own in
the past enough to know that passwords weren't impacted, and session
tokens were invalid, but the others didn't register to me when I
grepped the code-base.

> And yes, it is very important to keep it secret. The worst case
> scenario for secret key leakage, in particular configurations, is
> arbitrary remote code execution.

Could you elaborate on how such remote-code execution would happen?

Thanks,

-Tim




-- 
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/20140520152727.754c92c2%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.


Re: What happens when secret key is lost?

2014-05-20 Thread Erik Cederstrand
Den 20/05/2014 kl. 20.40 skrev Henning Sprang :

> Also, if it should be kept secret, I guess it's safe to assume that
> using an online generator like
> https://djskgen.herokuapp.com/ is not the smartest idea one can come
> up with, right?

You can use any random string, but you could also install django_extensions and 
do:

./manage.py generate_secret_key

Erik

-- 
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/3BDD0ED7-0FCC-41CE-AF0C-DE558AB9E024%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Hiring Python engineers in Fairfax, VA!

2014-05-20 Thread Jace Wieser
http://www.indeed.com/job/software-engineer-web-developer-python-django-f1adb67543d9e0f9

*Software Engineer / Web Developer (Python, Django)* 
Phase 5 Group - Fairfax, VA

Internet Software Engineer / Web Developer / Full Stack Engineer / Software 
Developer

We are looking for a great coder who has experience with Python, Django, 
Postgres, Git, HTML5, Heroku, responsive object-oriented web design, and 
good communication skills. iOS/ChromeOS development a plus.

The hiring company, Phase 5 Group, is well established and profitable. 
Small team building a brand new product. Engineering only office in Fairfax 
near to Fair Oaks Mall. No telecommuting possible at this time. Local 
recruits only.

This is a permanent position for an Internet Software Engineer / Web 
Developer / Full Stack Engineer / Software Developer.

You will design and build scalable internet web-based software systems in a 
high-availability, high-performance Python / Django environment on Heroku.

Lead the technical level design, development, testing and debugging of 
software components and products.

Take ownership of product problems and issues including pro-actively 
communicating to coordinate activities.

Develop features in an Agile environment and quickly apply new software 
enhancements and improvement upgrades effectively.

Job Requirements:

Education: B.S. in Computer Science, Engineering.

Experience:
... Minimum 2+ years "hands-on" Internet/web software development 
experience.
... Experience in development on Unix, Linux, or Solaris platforms.
... Strong object-oriented design & development skills.

Skills and Abilities:
... Expert-level Python development skills, Django familiarity.
... Experience with exception handling, namespaces, and 
internationalization.
... Familiarity with database applications and SQL is highly desirable.
... Strong analytical, communication, and problem solving skills.
... Team-oriented individual, energetic, results oriented, and interested 
in quality.
... Strong knowledge of data structures, algorithms, and fundamental 
concepts.
... Fluent in object-oriented programming languages, such as Python.
... Familiarity with Heroku is desirable, but not required.

-- 
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/e282d7a5-51b6-42c4-8600-30cdcb44e55c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


issues with django-organizations

2014-05-20 Thread Marcela Campo
Hi,
  Has anyone tried to use django-organizations? I am new to Django and 
trying to use that egg but just having issues as soon as I install it. 
After configuring it in my app I am getting the following error

Exception Type: ImportError  Exception Value: 

cannot import name registration_backend

 Exception Location: 
/home/chelis/development/python/Envs/eiwaenv/local/lib/python2.7/site-packages/organizations/views.py
 
in , line 15



When I look at the installation done with pip install at site-packages, I 
find that the __init__.py file has only the invitation backend and not the 
registration one.

Has someone stumbled upon this before?

Thanks!
Marcela


-- 
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/b9d30bc8-c741-4f21-8370-43fa7eeb841e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


The installation instructions for Windows is based on Python 3.4 But The MySQL connectors for Python are only for 2.7, 3.2 and 3.3

2014-05-20 Thread Varuna Seneviratna
The installation instructions for Windows is based on Python 3.4 But The
MySQL connectors for Python are only for 2.7, 3.2 and 3.3
What is the solution the problem?


Varuna

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


Many links to one function in url.py

2014-05-20 Thread Jun Tanaka
Hi there.


I hope to know the solution for the following:
say, there are several links to one function but I would like to identify 
which link that come from.

url.py looks

(r'^link1/$', 'project.apps.main.get'),
(r'^link2/$', 'project.apps.main.get'),
(r'^link3/$', 'project.apps.main.get'),
(r'^link4/$', 'project.apps.main.get'),

In 'get' function, how can I know which link does that come from? Later, I 
want to get a parameter , 1, 2, 3, 4 in that function. 

If anyone have a good idea? please teach me.

-- 
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/77f682ff-aae7-4081-88d6-d0415dd7eba4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many links to one function in url.py

2014-05-20 Thread Lucas Klassmann
Hi Jun,

Try this:

Put only this line in urls.py

url(r'^link/(?P<*identifier*>\d+)/$', 'project.apps.main.get'),


And in your view, add *identifier* as argument in function:

def get(request, *identifier*):
...
return HttpResponse(u'Identifier %d' % *identifier*)

Note that *identifier* is a *int* and you must use link as */link/1*

Read more:
https://docs.djangoproject.com/en/dev/topics/http/urls/

Cheers.

-- 
Lucas Klassmann
Software Developer
Email: lucasklassm...@gmail.com
Web site: http://www.lucasklassmann.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOz50p%2BVm1ZLvUmpDoP2HTVWEU-azTdk61fZJ51SWVuMWnfcdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django export the CSV file of objects form databas

2014-05-20 Thread hito koto
 Hello,

I have the following errors: why append is not done?
AttributeError at /export_excel/ 

'int' object has no attribute 'append'

 Request Method: GET  Request URL: http://article/export_excel/  Django 
Version: 1.6.2  Exception Type: AttributeError  Exception Value: 

'int' object has no attribute 'append'

 Exception Location: /var/www/html/staff/views.py in export_excel, line 181  
Python 
Executable: /usr/bin/python  Python Version: 2.6.6  Python Path: 

['/usr/lib/python2.6/site-packages/pip-1.5.2-py2.6.egg',
 '/usr/lib64/python26.zip',
 '/usr/lib64/python2.6',
 '/usr/lib64/python2.6/plat-linux2',
 '/usr/lib64/python2.6/lib-tk',
 '/usr/lib64/python2.6/lib-old',
 '/usr/lib64/python2.6/lib-dynload',
 '/usr/lib64/python2.6/site-packages',
 '/usr/lib/python2.6/site-packages',
 '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info',
 '/var/www/html/ihttest/ihttcs_test/kojin',
 '/var/www/html/ihttest/ihttcs_test/kojin/static/']

 Server time: Wed, 21 May 2014 12:15:09 +0900  
Traceback Switch to copy-and-paste 
view 
   
   - /usr/lib/python2.6/site-packages/django/core/handlers/base.py in 
   get_response 
   1. 
  
  response = wrapped_callback(request, *callback_args, 
**callback_kwargs)
  
  ...
▶ Local vars  
   - /var/www/html/staff/views.py in export_excel 
   1. 
  
  row[0][0].append(a)
  
  ...
▶ Local vars 
   

This is my views.py:

def export_excel(request):
response = HttpResponse(mimetype='application/vnd.ms-excel; 
charset="Shift_JIS"')
response['Content-Disposition'] = 'attachment; filename=file.csv'
writer = csv.writer(response)
titles = 
["No","名前".encode("Shift_JIS"),"日付".encode("Shift_JIS"),"出勤時間".encode("Shift_JIS"),
 
"退勤>時間".encode("Shift_JIS")]
writer.writerow(titles)
obj_all = Myattendance.objects.filter(id = 1).values_list('user', 
'contact_date', 'contact_time').order_by("-contact_time")
lea = Myleavework.objects.filter(id = 
1).values_list('contact_time').order_by('-contact_time')

row = [[0 for i in range(5)] for i in range(31)]
for a in obj_all.filter().values_list('user_id'):
row[0][0].append(a)
for b in obj_all.filter().values_list('contact_date'):
row[0][1].append(b)
for c in obj_all.filter().values_list('contact_time'):
row[0][2].aapend(c)

writer.writerow(row)
return response



-- 
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/6d23e2e5-397d-4ea6-aa48-0bbaddefc42e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django export the CSV file of objects form databas

2014-05-20 Thread Erik Cederstrand
Den 21/05/2014 kl. 05.21 skrev hito koto :

> Hello,
> 
> I have the following errors: why append is not done?
> 
> row = [[0 for i in range(5)] for i in range(31)]

Here you are creating a list of lists of 0's (a 2-dimensional matrix of ints).

> for a in obj_all.filter().values_list('user_id'):
> row[0][0].append(a)

Here, row[0][0] points to an int. You can't append to an int. Without knowing 
what you want to achieve, either initialize your list of lists with lists 
instead of 0's, or do "row[0][0] += a" instead.

> for b in obj_all.filter().values_list('contact_date'):
> row[0][1].append(b)
> for c in obj_all.filter().values_list('contact_time'):
> row[0][2].aapend(c)

Spelling error.

Erik

-- 
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/E9B38CD2-1D77-4D04-888C-2AE611EF0322%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.