Re: CAS and Django cache

2011-10-26 Thread Dan Julius
Couldn't that potentially overwrite a value set by a different thread?

Dan

On Thu, Oct 27, 2011 at 7:13 AM, Kurtis Mullins wrote:

> umm, I'm not sure if "check-and-set" is some cache-specific lingo or not.
> But if you want to see if a value isn't set, check to see if it's None
> type... example:
>
> if cache.get('key') is None:
> cache.set('key', 'value', cache_seconds)
>
> Sorry if that's not at all what you're talking about :)
>
>
> On Wed, Oct 26, 2011 at 6:29 PM, dmitry b  wrote:
>
>> Can I do check-and-set operations using Django's cache api?
>>
>>
>> Thanks
>> D.
>>
>> --
>> 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.
>>
>>
>  --
> 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.
>

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



No module named django after upgrade to os x Lion

2011-10-26 Thread angelika
Hello,

I'm new to both Python and Django. A few months ago, I installed
Django on my mac (running Snow Leopard). I took me quite some time,
but I got it running. After that I didn't get around to doing anything
with it. A few weeks ago, I upgraded my mac to run Lion and now, when
I type import django in the python interpreter, it says No module
named django.

I found someone who had had a similar problem, and I'm guessing it
could be connected to the fact that Lion comes with Python 2.7.1? My
Django version is 1.2.5. Again, I know almost nothing about Python, so
I could be way off base. Any ideas how I can solve this, or find out
what the problem is?

/Angelika

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



Optimisation Models

2011-10-26 Thread Suprnaturall
Optimisation Model

Hi everyone,

I'm working on the optimization of the model of my app. The goal is to
limit the request to the database.
In this webapp every user can follow users (like twitter), and when
someone you follow publish an article, each followers reveive a mail.
I'm wondering what is the best choice of models between this 2
example :

class UserProfile(models.Model):
...
followers = ManyToMany(self)

Or

class Followers(models.Model):
poster = OneToOne(UserProfile)
followers = ManyToMany(UserProfile)


First i was thinking about the example1, but I'm afraid that of each
time I will do a UserProfile.objects.get DJANGO join UserProfile table
to itself
in order to retrieve all the followers.

What do you think ?

Thx for your help :)

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



Accuracy of GeoIP?

2011-10-26 Thread Alan
Does anyone have experience with the accuracy of GeoIP? I'm getting
locations that are wildly off...

When I plug in the IP from http://whatismyipaddress.com/ I get
somewhere in the middle of Kansas when I'm in Chicago.

On the other hand using a Google IP address (mentioned in the example
below) correctly gives the lat/long of Mountain View

https://docs.djangoproject.com/en/dev/ref/contrib/gis/geoip/

I'm referencing data donwloaded from MaxMind:
http://geolite.maxmind.com/download/geoip/database/
As instructed by the link above.

I didn't run into any installation problems, so I assume there's a
data discrepancy somewhere; does anyone know of any known issues?

Thanks

-- 
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: CAS and Django cache

2011-10-26 Thread Kurtis Mullins
umm, I'm not sure if "check-and-set" is some cache-specific lingo or not.
But if you want to see if a value isn't set, check to see if it's None
type... example:

if cache.get('key') is None:
cache.set('key', 'value', cache_seconds)

Sorry if that's not at all what you're talking about :)

On Wed, Oct 26, 2011 at 6:29 PM, dmitry b  wrote:

> Can I do check-and-set operations using Django's cache api?
>
>
> Thanks
> D.
>
> --
> 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.
>
>

-- 
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: New member question about developing in Ubuntu Server

2011-10-26 Thread Andre Terra
Hello Ethan,

Welcome to Django, the web framework for people with deadlines and great taste!

Django absolutely does not require access to the builtin (or contrib,
as we call it on djangoland) admin app in order for you to configure
models.

A model is a representation of a way to store data, which in regular
Django setups is a description of a database table.

In order to define said table, one needs only a little knowledge and a
text editor so that models.py can be edited, which is where model
definitions live.

The admin is simply a generic web application that ships with django
in order to help you get some actual data in those tables in little
time. It is not, contrary to what you may have been led to believe, a
prerequisite to working with Django.

In fact, the further you go from basic CRUD functionality, the harder
it gets to make the admin app fit to your requirements.

To sum it all up, a model is defined in models.py, and the admin is
one of many ways to add rows to your database tables.

Having said that, I must recommend that you develop locally at first
so that you can leverage the features provided by the dev server,
namely auto reloading on code changes and handy debugging tools.

While you're at it, look up virtualenv. You'll thank me eventually!

Good luck and happy coding!


Cheers,
AT

On 10/26/11, Ethan Drower  wrote:
> Hey all,
>
> I am a brand new developer to django and had a question. I've
> successfully installed django on my remote ubuntu server and have
> already started going through tutorials.  I notice that they all
> require access of the admin console through a browser in order to
> configure models etc.  If i'm remoted into my ubuntu server I cannot
> view these very easily (w3m doesn't quite cut it).  So i was wondering
> what the best environment to develop in django is, do I need a gui to
> develop effectively?  I hope that question was specific enough, thank
> you in advance for the responses!
>
> --
> 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.
>
>

-- 
Sent from my mobile device

-- 
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: Long usernames in auth_user?

2011-10-26 Thread Andre Terra
Then again, you can't assume an email to not have spaces as "John
Doe"@example.com is a valid email per the RFC.

If you *really* need flexibility, have a UserProfile model with a
OneToOne relation to User and your imagination will be the only limit.


Cheers,
AT

On 10/26/11, Kurtis Mullins  wrote:
> Check out userena as well. But a custom authentication back-end was the
> approach I originally took. And to answer your question, yes -- your chances
> of finding people w/ email addresses longer than 75 chars are less than
> finding people w/ 30 chars -- but still a limitation none-the-less as there
> is no limitation on how long an email address can be.
>
> On Wed, Oct 26, 2011 at 5:03 PM, Joakim Hove  wrote:
>
>> OK;
>>
>> thanks I was afraid it was not entirely straightforward.
>>
>> On Oct 26, 10:52 pm, Donald Stufft  wrote:
>> > This is a known limitation and it's something that people _want_ to get
>> fixed (but just merely increasing the length isn't helpful, because soon
>> someone comes along with the new length + 1 and the same problem occurs).
>>
>> Now - of course the problem can easily crop up again by just
>> increasing length; but if the username length and the email length at
>> least default to the same value (the email field has length 75) the
>> failure will at least be simultaneous - and the usage pattern I
>> describe will work until the 75 characters e-mail limit is reached. So
>> although by no means a full solution, increasing the username length
>> to 75 would in my opinion be a very simple fix with some benefit?
>>
>> Joakim
>>
>> --
>> 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.
>>
>>
>
> --
> 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.
>
>

-- 
Sent from my mobile device

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



New member question about developing in Ubuntu Server

2011-10-26 Thread Ethan Drower
Hey all,

I am a brand new developer to django and had a question. I've
successfully installed django on my remote ubuntu server and have
already started going through tutorials.  I notice that they all
require access of the admin console through a browser in order to
configure models etc.  If i'm remoted into my ubuntu server I cannot
view these very easily (w3m doesn't quite cut it).  So i was wondering
what the best environment to develop in django is, do I need a gui to
develop effectively?  I hope that question was specific enough, thank
you in advance for the responses!

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



CAS and Django cache

2011-10-26 Thread dmitry b
Can I do check-and-set operations using Django's cache api?


Thanks
D.

-- 
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: Deploying Django

2011-10-26 Thread Javier Guerra Giraldez
On Wed, Oct 26, 2011 at 5:14 PM, sakthi  wrote:
> i installed mod_python and

that's where you got it wrong.

mod_python is obsolete and deprecated.  the supported way to deploy
python apps with apache is mod_wsgi.  check

https://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/

-- 
Javier

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



Possible to run manage.py sqlall [appname] without db connection?

2011-10-26 Thread Jason
I need to be able to output the table creation code but I don't
necessarily have access to a database.

Why does simply outputting the SQL require first connection to a
database?

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



Deploying Django

2011-10-26 Thread sakthi
Hi all,

I am running Apache in linux. I need to deploy my django app to it, so
i installed mod_python and configured the apache according to it. Then
I got an annoying error at the first page, that I couldn't figure out.
Please suggest a solution.

The error is:

ImportError at /gpa
No module named urls

Request Method: GET
Request URL:http://localhost/gpac/gpa
Django Version: 1.2.5
Exception Type: ImportError
Exception Value:

No module named urls

Exception Location: /usr/lib/pymodules/python2.7/django/utils/
importlib.py in import_module, line 35
Python Executable:  /usr/bin/python
Python Version: 2.7.1
Python Path:['/home/saki/', '/var/www', '/usr/lib/pymodules/
python2.7', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/
usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/
python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/
usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/
PIL', '/usr/lib/pymodules/python2.7/gtk-2.0', '/usr/lib/python2.7/dist-
packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0']

My apache conf file:

LoadModule python_module /usr/lib/apache2/modules/mod_python.so


SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE gpc.settings
PythonOption django.root /gpac
PythonPath "['/home/saki/','/var/www']+sys.path"
PythonDebug On


gpc is the name of the app( directory containing all the source files
of the app.)

Please help

Thank you :)

-- 
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: Long usernames in auth_user?

2011-10-26 Thread Kurtis Mullins
Check out userena as well. But a custom authentication back-end was the
approach I originally took. And to answer your question, yes -- your chances
of finding people w/ email addresses longer than 75 chars are less than
finding people w/ 30 chars -- but still a limitation none-the-less as there
is no limitation on how long an email address can be.

On Wed, Oct 26, 2011 at 5:03 PM, Joakim Hove  wrote:

> OK;
>
> thanks I was afraid it was not entirely straightforward.
>
> On Oct 26, 10:52 pm, Donald Stufft  wrote:
> > This is a known limitation and it's something that people _want_ to get
> fixed (but just merely increasing the length isn't helpful, because soon
> someone comes along with the new length + 1 and the same problem occurs).
>
> Now - of course the problem can easily crop up again by just
> increasing length; but if the username length and the email length at
> least default to the same value (the email field has length 75) the
> failure will at least be simultaneous - and the usage pattern I
> describe will work until the 75 characters e-mail limit is reached. So
> although by no means a full solution, increasing the username length
> to 75 would in my opinion be a very simple fix with some benefit?
>
> Joakim
>
> --
> 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.
>
>

-- 
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: Long usernames in auth_user?

2011-10-26 Thread Joakim Hove
OK;

thanks I was afraid it was not entirely straightforward.

On Oct 26, 10:52 pm, Donald Stufft  wrote:
> This is a known limitation and it's something that people _want_ to get fixed 
> (but just merely increasing the length isn't helpful, because soon someone 
> comes along with the new length + 1 and the same problem occurs).

Now - of course the problem can easily crop up again by just
increasing length; but if the username length and the email length at
least default to the same value (the email field has length 75) the
failure will at least be simultaneous - and the usage pattern I
describe will work until the 75 characters e-mail limit is reached. So
although by no means a full solution, increasing the username length
to 75 would in my opinion be a very simple fix with some benefit?

Joakim

-- 
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: Long usernames in auth_user?

2011-10-26 Thread Andre Terra
On Wed, Oct 26, 2011 at 6:52 PM, Donald Stufft wrote:

> The other method is to create your own auth handler (...)
>

http://djangosnippets.org/snippets/1001/


Cheers,
AT

-- 
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: Long usernames in auth_user?

2011-10-26 Thread Donald Stufft
This is a known limitation and it's something that people _want_ to get fixed 
(but just merely increasing the length isn't helpful, because soon someone 
comes along with the new length + 1 and the same problem occurs). The issue is 
that the django.contrib.auth User model while providing a minimum (sort of) set 
of fields for a user, doesn't let you enhance it's internals very well. I think 
the core dev's are mostly waiting for someone to come up with a good solution 
to this problem. 

Now to answer your other question. 

There are 2 general ways of handling this, and neither one is perfect. One is 
to do as you did and modify the db to allow longer usernames, also being 
careful to modify anyplace that validates that the length is 30 so that it 
works across the sites.

The other method is to create your own auth handler (Pinax comes with one) that 
let's you authenticate against the email field on auth.User. Then in your 
signup process you save their email address to this field, and generate the 
username (I'm fond of UUID's for this). The final (optional) piece of this 
puzzle is to monkey patch User.__unicode__ to return self.email instead of 
self.username. 


On Wednesday, October 26, 2011 at 4:38 PM, Joakim Hove wrote:

> Hello,
> 
> I have been using a (in general quite popular I think ...) convention
> where the e-mail address has been used as username. I have solved this
> by asking the user for an e-mail address and a password, and then used
> the supplied e-mail address both as username and e-mail address when
> instantiating a User object. This has worked fine up until now.
> 
> Now suddenly someone came along with an e-mail address which was
> longer than the 30 characters limit imposed on the username; and
> things went to pieces. I have Googled this topic but did not find any
> clear cut simple solution, altough I am definitely not the first one
> to stumble over this problem.
> 
> So two questions:
> 
> 1) I modified the (development) database directly increasing the field
> size from 30 to 75; and that seemed to work nicely; but I am not very
> comfortable about the solution. What do you say?
> 
> 2) Any chance of changing this in a future release?
> 
> Joakim
> 
> -- 
> 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 
> (mailto:django-users@googlegroups.com).
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com 
> (mailto:django-users+unsubscr...@googlegroups.com).
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 


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



Long usernames in auth_user?

2011-10-26 Thread Joakim Hove
Hello,

I have been using a (in general quite popular I think ...) convention
where the e-mail address has been used as username. I have solved this
by asking the user for an e-mail address and a password, and then used
the supplied e-mail address both as username and e-mail address when
instantiating a User object. This has worked fine up until now.

Now suddenly someone came along with an e-mail address which was
longer than the 30 characters limit imposed on the username; and
things went to pieces. I have Googled this topic but did not find any
clear cut simple solution, altough I am definitely not the first one
to stumble over this problem.

So two questions:

1) I modified the (development) database directly increasing the field
size from 30 to 75; and that seemed to work nicely; but I am not very
comfortable about the solution. What do you say?

2) Any chance of changing this in a future release?

Joakim

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



Help Required with Image Upload

2011-10-26 Thread Swaroop Shankar V
Hello All,
Am pretty new to Django. I am trying to create a form which will upload an
image and then enable the user to crop visually (using JCrop plugin). Am
not completely sure on how to implement this in Django. I am thinking of
first saving the uploaded image into the disk as a jpeg file and then load
and display the image as an overlay where the user can crop the image. I am
able to create a form with the image field and then am passing over
request.FILE to a function called handle_uploaded_image. Following is
my handle_uploaded_image function

def handle_uploaded_image(self, image):
"""
This function is to handle uploaded image file
"""
imageFile = Image.open(StringIO.StringIO(image.read()))
fileName = hashlib.md5(imageFile.getvalue()).hexdigest()+'.jpg'

Now i am kind of confused on how to convert the uploaded image into jpg
using PIL, and then saving into the disk. I had defined a field in my model
to save the image file name which is as follows:

class UserProfile(models.Model):

avatar = models.ImageField(_('Avatar'),upload_to=settings.IMAGE_UPLOAD_PATH,
null=True)

I did this based on the django documentation, but it tells something about
binding the form which am not able to correctly understand. Why do we need
to bind a form with image field. Also whats the use of giving upload_to in
model image field? Thanks in advance for any help.

Regards,

Swaroop Shankar V

-- 
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: Field.Choices in Template

2011-10-26 Thread Kurtis Mullins
Hey Guys,

I hate to bother you again. But -- is there a way to get the currently
selected data from this set? For example, a user hits the page and all
choices are displayed fine. But, they pick some choices. They haven't
finished editing the form or maybe they made a mistake, anyways they land in
the form_invalid land. I'd like to be able to use this same technique to
make sure I properly display what the user has selected thus-far.

Thanks!

On Tue, Oct 25, 2011 at 8:05 AM, Andre Terra  wrote:

> I remember trying to help you with this on IRC, Kurtis. I've had the
> same problem before, but I could never remember that BoundFields have
> a field attribute.. If there isn't a note in the docs (or even better,
> an example), I'll make sure to write a patch in the next few days.
>
>
> Cheers,
> AT
>
> On 10/25/11, Kurtis  wrote:
> > Thank you so much for this, Tom! I've asked this question quite a few
> > times in IRC and couldn't come across the answer I was looking for. I
> > figured it was possible, I just had no idea how to access it. Much
> > appreciation!
> >
> > On Oct 24, 11:26 am, Tom Evans  wrote:
> >> On Thu, Oct 20, 2011 at 8:37 PM, Kurtis 
> wrote:
> >> > Hey,
> >>
> >> > I'm trying to build a custom template for my ModelForm. My ModelForm
> >> > contains several M2M fields. If I run the ModelForm.as_view and then
> >> > in my template print {{ form.as_p }} it'll automagically display those
> >> > choices.
> >>
> >> > Now what I want to do is take advantage of that magic and print out
> >> > those choices myself in my template. For example:
> >>
> >> > {% for choice in form.genres.choices %}
> >> >{{ choice }}
> >> > {% endfor %}
> >>
> >> > ... but it doesn't work. it doesn't print anything. I tried reading
> >> > through the source code of the forms.py and fields.py from 1.3 but
> >> > didn't get very far.
> >>
> >> When you access a form field from a template, the field returned is a
> >> BoundField, not the field attribute from the form class. From the
> >> BoundField object, you can access the form field on the field
> >> attribute, eg:
> >>
> >> {% for choice in form.genres.field.choices %}
> >>{{ choice }}
> >> {% endfor %}
> >>
> >> Cheers
> >>
> >> Tom
> >
> > --
> > 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.
> >
> >
>
> --
> Sent from my mobile device
>
> --
> 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.
>
>

-- 
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: apache and remote_user

2011-10-26 Thread Tim
Thanks David, 
Yes I've read and re-read that page. I think my problem is coming from 
Apache though.
It looks like my next step is more research on apache authorization from a 
domain.

thanks,
--Tim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Ynruy3XKmdgJ.
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: Multiple database Router

2011-10-26 Thread Simon Riggs
On Wed, Oct 26, 2011 at 4:19 PM, Tom Evans  wrote:

> Sure, all cars run on top of tarmac,
> but you are unlikely to find a tarmac specialist on a car forum, you
> are better off asking in a more appropriate place.

Happy to bite on that one and am chuckling away at that.

Databases are the engines, and yes, you do find engine specialists in
car forums because cars are the raison d'etre. If Django was a badly
designed car, you wouldn't find such people, that's true.

I'm sure the Red Bull team have similar discussions about whose piece
of the car is most important.

-- 
 Simon Riggs   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

-- 
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: no return from image_set.all yet code almost identical

2011-10-26 Thread MikeKJ

My bad, I found the deliberate error!
-- 
View this message in context: 
http://old.nabble.com/no-return-from-image_set.all-yet-code-almost-identical-tp32723239p32725680.html
Sent from the django-users mailing list archive at Nabble.com.

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



Weird situation about static file

2011-10-26 Thread Tsung-Hsien
I just change some style of css, but after runserver, the css is
nothing change.
I not only deleted the image file in the static folder, but deleted
whole static folder and the website still show the image and css.
only use in localhost, even doesn't deploy to server yet.
I don't know why that happened

Below is my setting

MEDIA_ROOT = 'C:/Python27/Lib/site-packages/django/bin/mysite/media'

# URL that handles the media served from MEDIA_ROOT. Make sure to use
a
# trailing slash.
# Examples: "http://media.lawrence.com/media/";, "http://example.com/
media/"
MEDIA_URL = '/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static
files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = 'C:/Python27/Lib/site-packages/django/bin/mysite/static'

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/";
STATIC_URL = '/static/'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/";, "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'

# Additional locations of static files
STATICFILES_DIRS = (
r'C:\Python27\Lib\site-packages\django\bin\mysite\blog\static',
r'C:\Python27\Lib\site-packages\django\bin\mysite\media',
# Put strings here, like "/home/html/static" or "C:/www/django/
static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)


Thanks!

-- 
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: no return from image_set.all yet code almost identical

2011-10-26 Thread MikeKJ

update I have moved all the classes into the one model, image_sets   ...
from django.db import models
from smartpages.models import SmartPage

POSITIONCHOICES = [
('1', 'Top'),
('2', 'Bottom')
]

class Set(models.Model):
assigned_page = models.ForeignKey(SmartPage, help_text='The smartpage
this set is assigned to')
position = models.CharField(choices=POSITIONCHOICES, max_length=1)
name = models.CharField(max_length=50, help_text='An identifying name,
like the name of the smartpage')

def __unicode__(self):
return self.name

class Image(models.Model):
page = models.ForeignKey(Set)
image = models.ImageField(upload_to='page_sets')

class HeadSet(models.Model):
assigned_page = models.ForeignKey(SmartPage, help_text='The smartpage
this set is assigned to')
name = models.CharField(max_length=50, help_text='An identifying name,
like the name of the smartpage')

def __unicode__(self):
return self.name

class HeadImage(models.Model):
page = models.ForeignKey(HeadSet)
image = models.ImageField(upload_to='head_sets')

The problem still persists!
shelling it still shows

imsettop and imsetbottrom return image_set.all()
headset doesnt, yet the code to get all three are almost identical




-- 
View this message in context: 
http://old.nabble.com/no-return-from-image_set.all-yet-code-almost-identical-tp32723239p32725569.html
Sent from the django-users mailing list archive at Nabble.com.

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



column user_id is not unique

2011-10-26 Thread Shark
There is problem in this project
I use Auth User and foreign key in anther table  "geoFeeds" and when
adding data to table gepFeed am error happened

column user_id is not unique

when changing the userId it add one time but the second time it fails
and give this error I don't know why

this is the code

models.py

from django.db import models
from django.contrib.auth.models import User

class GeoFeed(models.Model):
user = models.ForeignKey(User, unique=False)
link = models.URLField()
name = models.CharField(max_length=100)
def __unicode__(self):
return self.id


and this is the function that add feeds in view



def addFeed(request):
ok = False

if request.method == 'POST': # if the form has been submitted
fname = request.POST.get('fname', '') # feed name
flink = request.POST.get('flink', '') # feed link

if fname is not None and flink is not None:
# save
u = User.objects.get(pk = 2) # pre-defined user till amr
finishes user-sys
f = GeoFeed(user = u, link = flink, name = fname)
f.save()

return render_to_response('add_feed.html', {'ok': ok},
RequestContext(request))

-- 
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: Revamping and existing project

2011-10-26 Thread Tiago Almeida
Hi,

I think you need to be more specific. What do you mean with "i want to
be able to view the page as i edit it". What page? Do you mean what
you see in the browser? If so, you need something like
aloha editor (http://aloha-editor.org/) and you need to integrate it
in your app.

Best regards,


On Oct 25, 9:13 pm, jhames  wrote:
> hello,
>
> i am an absolute beginner with web dev, so bear with me here. i need
> to make several changes to my campany's django apps. nothing too
> complicated. in their settings.py file, i notice that they connect to
> a mysql database. i want to be able to view the page as i edit it but
> i don't understand how to do this with an existing mysql database. all
> the images for the site are stored in this database.
>
> any suggestions on how to get started here?
>
> thank you!
> james

-- 
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: NEWBIE: using django without a model.

2011-10-26 Thread damola oyeniyi
Apache pig is a scripting tool to analyze data in hadoop clusters


Sent from Yahoo! Mail on Android

-- 
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: block behavior does not work as documented with respect to autoescape

2011-10-26 Thread Peter Banka
Awesome! Thank you.

On Tue, Oct 25, 2011 at 8:10 AM, psbanka  wrote:

> In the current Django 1.3 documentation on templates
> (https://docs.djangoproject.com/en/1.3/topics/templates/#for-template-
> blocks), the documentation mentions the following:
>
> "The auto-escaping tag passes its effect onto templates that extend
> the current one as well as templates included via the include tag,
> just like all block tags"
>
> And the following example is provided:
>   # base.html
>
>   {% autoescape off %}
>   {% block title %}{% endblock %}
>   {% block content %}
>   {% endblock %}
>   {% endautoescape %}
>
>
> However, this doesn't actually seem to work, as illustrated in the
> following example,
>   a = '''
>   {% autoescape off %}
>   {% block title %}{{ hello }}{% endblock %}
>   {% block content %}
>   {% endblock %}
>   {% endautoescape %}
>   '''
>   from django.template import Context, Template, TemplateSyntaxError
>   django_template = Template(a)
>   context = Context({"hello": 'world'})
>
>   print django_template.render(context)
>
> when encountering the line "django_template = Template(a)", django
> throws an exception:
> django.template.base.TemplateSyntaxError: Invalid block tag: 'block',
> expected 'endautoescape'
>
> Am I reading the documentation wrong, or is there a Django error here?
>
> Thanks,
> --psbanka

-- 
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: NEWBIE: using django without a model.

2011-10-26 Thread MikeKJ

If no database requirement then you dont a model just a view and a template
but I have no idea what pig!. is


damola oyeniyi wrote:
> 
> Hi,
> 
> I am trying to create a simple query page using django and pig!. I would
> not be needing a database, so I'm not sure if a model is involved. My pig
> script will crunch multiple files containing lots of lines with data of
> the same format. I want to try and display results from that query in a
> web page.
> 
> Will I need a model, and if I do, how do I go about it?
> 
> Regards,
> Damola
> 
> 
> Sent from Yahoo! Mail on Android
> 
> -- 
> 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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/NEWBIE%3A-using-django-without-a-model.-tp32725297p32725475.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
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: NEWBIE: using django without a model.

2011-10-26 Thread Dipo Elegbede
In my opinion as a starter too, I don't think you need a model if you are
not using a database.
Others could have their opinions.

On 26 Oct 2011 16:37, "damola oyeniyi"  wrote:

> Hi,
>
> I am trying to create a simple query page using django and pig!. I would
> not be needing a database, so I'm not sure if a model is involved. My pig
> script will crunch multiple files containing lots of lines with data of the
> same format. I want to try and display results from that query in a web
> page.
>
> Will I need a model, and if I do, how do I go about it?
>
> Regards,
> Damola
>
>
> Sent from Yahoo! Mail on Android
>
>  --
> * From: * Gabriela ;
> * To: * Django users ;
> * Subject: * Multiple database Router
> * Sent: * Wed, Oct 26, 2011 2:24:06 PM
>
>   I need to synchronize multiple databases, i have readed the
> https://docs.djangoproject.com/en/1.3/topics/db/multi-db/ where they
> explain how to make this.
>
>
> but i dont understand what do they refer with 'myapp' and 'other', are
> this tables from the database? I dont understand what do they mean.
>
> I just want to compare and synchronize two databases db1 and db2, that
> have the same tables but different data.
>
> can anyone suggest what can i do
>
> Thanks
>
> --
> 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.
>
> --
> 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.
>

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



NEWBIE: using django without a model.

2011-10-26 Thread damola oyeniyi
Hi,

I am trying to create a simple query page using django and pig!. I would not be 
needing a database, so I'm not sure if a model is involved. My pig script will 
crunch multiple files containing lots of lines with data of the same format. I 
want to try and display results from that query in a web page.

Will I need a model, and if I do, how do I go about it?

Regards,
Damola


Sent from Yahoo! Mail on Android

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



combining media of more than one form or needed for the rest of the page

2011-10-26 Thread Henrik Genssen
Hi,

I wonder how you all combine media of forms or other stuff in your page.
I read here one solution could be writing a template tag or filter to combine 
the media objects by simply using the + operator.

So how are you constructing your pages, if you are using templates? So far I 
used forms for input, but all other UI elements where
pasted into the HTML template in raw html e.g. an ajax table.

But a page does not only consist of forms - there could be:
- toolbar
- status bar
- (ajax-) tables
- context-menus
- tab controls
- javascript functions
- and what ever you like...

is there a raw concept on how to use more elements then forms or maybe even 
more than a concept, that I did not recognize?
How are you solving this?

regards

Henrik

-- 
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: Multiple database Router

2011-10-26 Thread Tom Evans
On Wed, Oct 26, 2011 at 3:59 PM, Gabriela  wrote:
> I need to implemente Asynchornous multimaster replication
> implemented in Linux and Windows OS
>
> Bucardo is a great option but it doesnt works in Windows
>
> Any help would be welcome, Im new in this and I need a solution, Im
> stuck installing softwares and configuring URLs and IPs
>
> Cheers
> Gabi
>

Whilst I get that you want to setup replication for a django site,
it's really not appropriate for this list. It's like going to a car
forum and talking about tarmac. Sure, all cars run on top of tarmac,
but you are unlikely to find a tarmac specialist on a car forum, you
are better off asking in a more appropriate place.

Since you mentioned Bucardo (3rd party postgresql replication) I would
recommend one of the lists on this page for postgresql:

http://www.postgresql.org/community/lists/

Postgresql has included its own built in replication system for a
while as well, you should also check out the docs I linked to earlier.

Cheers

Tom

-- 
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: Multiple database Router

2011-10-26 Thread Gabriela
I need to implemente Asynchornous multimaster replication
implemented in Linux and Windows OS

Bucardo is a great option but it doesnt works in Windows

Any help would be welcome, Im new in this and I need a solution, Im
stuck installing softwares and configuring URLs and IPs

Cheers
Gabi

On Oct 26, 4:52 pm, Tom Evans  wrote:
> On Wed, Oct 26, 2011 at 3:38 PM, Gabriela  wrote:
> > Thanks Tom,
>
> > so Django dont allow to make replication?
>
> Django is a web application framework, database replication is
> orthogonal to that.
>
> My current setup has a multi data centre, multi master replication,
> with a couple of read slaves in each data centre, but the only thing
> Django has to do with it is decide which database server to use,
> everything else is taken care of by the database software (MySQL).
>
> The only time you need 3rd party software DB replication is when you
> want either heterogeneous replication (eg, MySQL replicating from
> Oracle), or your DB software's own replication mechanisms are fragile.
>
> Docs on replication for MySQL and Postgres:
>
> http://dev.mysql.com/doc/refman/5.5/en/replication.htmlhttp://www.postgresql.org/docs/9.1/static/high-availability.html
>
> Cheers
>
> Tom

-- 
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: Multiple database Router

2011-10-26 Thread Tom Evans
On Wed, Oct 26, 2011 at 3:38 PM, Gabriela  wrote:
> Thanks Tom,
>
> so Django dont allow to make replication?
>

Django is a web application framework, database replication is
orthogonal to that.

My current setup has a multi data centre, multi master replication,
with a couple of read slaves in each data centre, but the only thing
Django has to do with it is decide which database server to use,
everything else is taken care of by the database software (MySQL).

The only time you need 3rd party software DB replication is when you
want either heterogeneous replication (eg, MySQL replicating from
Oracle), or your DB software's own replication mechanisms are fragile.

Docs on replication for MySQL and Postgres:

http://dev.mysql.com/doc/refman/5.5/en/replication.html
http://www.postgresql.org/docs/9.1/static/high-availability.html

Cheers

Tom

-- 
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: Multiple database Router

2011-10-26 Thread Gabriela
Can you suggest me , if you know, any software replicator, I had only
configure with RubyRep and SymmetricDS but I need more options? I have
been trying wit DBReplicator but is impossible. Do you handle this
theme about replication?

Cheers

On Oct 26, 4:38 pm, Gabriela  wrote:
> Thanks Tom,
>
> so Django dont allow to make replication?
>
> On Oct 26, 4:32 pm, Tom Evans  wrote:
>
> > On Wed, Oct 26, 2011 at 3:24 PM, Gabriela  wrote:
> > > I need to synchronize multiple databases, i have readed the
> > >https://docs.djangoproject.com/en/1.3/topics/db/multi-db/wherethey
> > > explain how to make this.
>
> > > but i dont understand what do they refer with 'myapp' and 'other', are
> > > this tables from the database? I dont understand what do they mean.
>
> > > I just want to compare and synchronize two databases db1 and db2, that
> > > have the same tables but different data.
>
> > > can anyone suggest what can i do
>
> > > Thanks
>
> > DB routers don't do that, they allow django to make a decision about
> > which database to query, based upon app, model, hints, etc etc.
>
> > If you want 'synchronization', you want DB replication. Most databases
> > support replication, MySQL replication is simple, PostgreSQL not so
> > much, but that is way off topic for a django list.
>
> > There are also tools you can use to compare two databases. Percona
> > toolkit has some excellent checksumming tools for checksumming MySQL
> > tables - to ensure that the same data is on both sides - and I'm sure
> > someone who knows what the equivalent is for Postgres will be along
> > shortly.
>
> > Cheers
>
> > Tom

-- 
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: Multiple database Router

2011-10-26 Thread Gabriela
Thanks Tom,

so Django dont allow to make replication?

On Oct 26, 4:32 pm, Tom Evans  wrote:
> On Wed, Oct 26, 2011 at 3:24 PM, Gabriela  wrote:
> > I need to synchronize multiple databases, i have readed the
> >https://docs.djangoproject.com/en/1.3/topics/db/multi-db/where they
> > explain how to make this.
>
> > but i dont understand what do they refer with 'myapp' and 'other', are
> > this tables from the database? I dont understand what do they mean.
>
> > I just want to compare and synchronize two databases db1 and db2, that
> > have the same tables but different data.
>
> > can anyone suggest what can i do
>
> > Thanks
>
> DB routers don't do that, they allow django to make a decision about
> which database to query, based upon app, model, hints, etc etc.
>
> If you want 'synchronization', you want DB replication. Most databases
> support replication, MySQL replication is simple, PostgreSQL not so
> much, but that is way off topic for a django list.
>
> There are also tools you can use to compare two databases. Percona
> toolkit has some excellent checksumming tools for checksumming MySQL
> tables - to ensure that the same data is on both sides - and I'm sure
> someone who knows what the equivalent is for Postgres will be along
> shortly.
>
> Cheers
>
> Tom

-- 
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: Custom upload handler in generic view

2011-10-26 Thread Andre Terra
AFAIK, it's also doable with apache, with little modification from the code
I provided. I just haven't had the chance to investigate the possibilities
yet.

Before I say anything else, I must admit I completely forgot to provide a
very important file for the upload progress thingy: the javascript file [1]
which fetches information from the server!

As for your question, I honestly can't say I'm an authority on the matter,
but from my understanding, the custom upload handler will do the talking
between django and nginx. The way upload handlers work is pretty much beyond
my knowledge, so for now I'm just going to accept the fact that it works :P


Cheers,
AT

[1]
https://github.com/drogus/jquery-upload-progress/blob/master/jquery.uploadProgress.js



On Wed, Oct 26, 2011 at 10:31 AM, hbf  wrote:

> Thanks for your reply and the detailed information.
>
> Your solution looks great, and I guess that using a web server-based
> solution (in contrast to a Django-based one) is much more efficient.
> What I do not understand in your setup is why, if you have
> HttpUploadProgressModule installed, you do need a custom upload
> handler and AJAX view? IIUC HttpUploadProgressModule is providing this
> for free, isn't it?
>
> Unfortunately, my hoster is not using nginx but Apache. Maybe there is
> a Django-compatible module for it out there;
> https://github.com/drogus/apache-upload-progress-module/ seems to be
> an option but I haven't tried it yet.
>
> Best,
> Kaspar
>
> On Oct 26, 2:18 pm, Andre Terra  wrote:
> > Are you using nginx by any chance? I use nginx and my setup is as
> follows:
> >
> > A upload.py with the custom handler and a view to yield progress result
> as
> > json [1], a template with some javascript [2] to fetch the json-formatted
> > progress result, some lines in nginx.conf [3] to tell it to keep track of
> > uploads (nginx must be compiled with HttpUploadProgressModule [4]) and a
> bit
> > of patience to get it up and running.
> >
> > I have compiled nginx for windows with that additional module. The
> > instructions are pretty much gone at this point, but I can zip the
> binaries
> > and send it your way should you need them.
> >
> > You will also notice that I use a /projects/mysite/mysite layout for my
> > django projects, which is consistent with the new layout in 1.4/trunk
> [5].
> >
> > I almost forgot! I'm also using a custom JSONMixin which calls get_data()
> on
> > ajax requests in any view that implements it and returns self.data (to be
> > set by self.get_data) as json [6].
> >
> > Best of luck!
> >
> > Cheers,
> > AT
> >
> > [1]http://dpaste.com/hold/641334/
> > [2]http://dpaste.com/hold/641337/
> > [3]http://dpaste.com/hold/641339/
> > [4]http://wiki.nginx.org/HttpUploadProgressModule
> > [5]
> https://docs.djangoproject.com/en/dev/intro/tutorial01/#creating-a-pr...
> > [6]http://dpaste.com/hold/641344/
> >
> >
> >
> >
> >
> >
> >
> > On Wed, Oct 26, 2011 at 9:21 AM, hbf  wrote:
> > > Dear all,
> >
> > > In order to provide progress feedback of file uploads I needed to
> > > install an upload handler for a specific view. This is documented for
> > > "classical" views at
> >
> > >https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#modif.
> ..
> >
> > > For generic views, however, I could not find any instructions and I
> > > came up with the following, which I would like to share:
> >
> > > # BEGIN OF CLASS
> > > from django.utils import importlib
> > > from django.core.exceptions import ImproperlyConfigured
> > > from django.views.decorators.csrf import csrf_protect
> >
> > > class UploadHandlerMixin(object):
> > >'''
> > >A mixin for Django generic views that installs a custom upload
> > > handler in front of
> > >the current chain of upload handlers.
> >
> > >You specify the handler to install by overriding the
> > > 'upload_handler' attribute of
> > >the class, specifying the module and class name in the form
> > > 'path.to.module.class':
> >
> > >class MyView(UploadHandlerMixin, View):
> > >upload_handler = 'path.to.module.MyUploadHandler'
> >
> > >If you do not override 'upload_handler', no additional upload
> > > handler will be
> > >installed.
> >
> > >If the CsrfViewMiddleware is installed (which is the default)
> > > then you must use
> > >your view as follows in your urls.py:
> >
> > >from django.views.decorators.csrf import csrf_exempt
> > >url(r'^.../$', csrf_exempt(MyView.as_view()), ...),
> >
> > >Internally, the UploadHandlerMixin mixin will install the
> > > upload handler and then
> > >perform the CSRF check. (This is necessary because the CSRF
> > > check inspects
> > >request.POST, and afterwards upload handlers cannot be
> > > changed, see documentation
> > >link given below.)
> >
> > >The handler is installed as described in the Django
> > > documentation "Modifying upload handlers
> > >o

Re: Multiple database Router

2011-10-26 Thread Tom Evans
On Wed, Oct 26, 2011 at 3:24 PM, Gabriela  wrote:
> I need to synchronize multiple databases, i have readed the
> https://docs.djangoproject.com/en/1.3/topics/db/multi-db/ where they
> explain how to make this.
>
>
> but i dont understand what do they refer with 'myapp' and 'other', are
> this tables from the database? I dont understand what do they mean.
>
> I just want to compare and synchronize two databases db1 and db2, that
> have the same tables but different data.
>
> can anyone suggest what can i do
>
> Thanks
>

DB routers don't do that, they allow django to make a decision about
which database to query, based upon app, model, hints, etc etc.

If you want 'synchronization', you want DB replication. Most databases
support replication, MySQL replication is simple, PostgreSQL not so
much, but that is way off topic for a django list.

There are also tools you can use to compare two databases. Percona
toolkit has some excellent checksumming tools for checksumming MySQL
tables - to ensure that the same data is on both sides - and I'm sure
someone who knows what the equivalent is for Postgres will be along
shortly.

Cheers

Tom

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



Multiple database Router

2011-10-26 Thread Gabriela
I need to synchronize multiple databases, i have readed the
https://docs.djangoproject.com/en/1.3/topics/db/multi-db/ where they
explain how to make this.


but i dont understand what do they refer with 'myapp' and 'other', are
this tables from the database? I dont understand what do they mean.

I just want to compare and synchronize two databases db1 and db2, that
have the same tables but different data.

can anyone suggest what can i do

Thanks

-- 
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: Custom upload handler in generic view

2011-10-26 Thread hbf
Thanks for your reply and the detailed information.

Your solution looks great, and I guess that using a web server-based
solution (in contrast to a Django-based one) is much more efficient.
What I do not understand in your setup is why, if you have
HttpUploadProgressModule installed, you do need a custom upload
handler and AJAX view? IIUC HttpUploadProgressModule is providing this
for free, isn't it?

Unfortunately, my hoster is not using nginx but Apache. Maybe there is
a Django-compatible module for it out there;
https://github.com/drogus/apache-upload-progress-module/ seems to be
an option but I haven't tried it yet.

Best,
Kaspar

On Oct 26, 2:18 pm, Andre Terra  wrote:
> Are you using nginx by any chance? I use nginx and my setup is as follows:
>
> A upload.py with the custom handler and a view to yield progress result as
> json [1], a template with some javascript [2] to fetch the json-formatted
> progress result, some lines in nginx.conf [3] to tell it to keep track of
> uploads (nginx must be compiled with HttpUploadProgressModule [4]) and a bit
> of patience to get it up and running.
>
> I have compiled nginx for windows with that additional module. The
> instructions are pretty much gone at this point, but I can zip the binaries
> and send it your way should you need them.
>
> You will also notice that I use a /projects/mysite/mysite layout for my
> django projects, which is consistent with the new layout in 1.4/trunk [5].
>
> I almost forgot! I'm also using a custom JSONMixin which calls get_data() on
> ajax requests in any view that implements it and returns self.data (to be
> set by self.get_data) as json [6].
>
> Best of luck!
>
> Cheers,
> AT
>
> [1]http://dpaste.com/hold/641334/
> [2]http://dpaste.com/hold/641337/
> [3]http://dpaste.com/hold/641339/
> [4]http://wiki.nginx.org/HttpUploadProgressModule
> [5]https://docs.djangoproject.com/en/dev/intro/tutorial01/#creating-a-pr...
> [6]http://dpaste.com/hold/641344/
>
>
>
>
>
>
>
> On Wed, Oct 26, 2011 at 9:21 AM, hbf  wrote:
> > Dear all,
>
> > In order to provide progress feedback of file uploads I needed to
> > install an upload handler for a specific view. This is documented for
> > "classical" views at
>
> >https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#modif...
>
> > For generic views, however, I could not find any instructions and I
> > came up with the following, which I would like to share:
>
> > # BEGIN OF CLASS
> > from django.utils import importlib
> > from django.core.exceptions import ImproperlyConfigured
> > from django.views.decorators.csrf import csrf_protect
>
> > class UploadHandlerMixin(object):
> >    '''
> >        A mixin for Django generic views that installs a custom upload
> > handler in front of
> >        the current chain of upload handlers.
>
> >        You specify the handler to install by overriding the
> > 'upload_handler' attribute of
> >        the class, specifying the module and class name in the form
> > 'path.to.module.class':
>
> >            class MyView(UploadHandlerMixin, View):
> >                upload_handler = 'path.to.module.MyUploadHandler'
>
> >        If you do not override 'upload_handler', no additional upload
> > handler will be
> >        installed.
>
> >        If the CsrfViewMiddleware is installed (which is the default)
> > then you must use
> >        your view as follows in your urls.py:
>
> >            from django.views.decorators.csrf import csrf_exempt
> >            url(r'^.../$', csrf_exempt(MyView.as_view()), ...),
>
> >        Internally, the UploadHandlerMixin mixin will install the
> > upload handler and then
> >        perform the CSRF check. (This is necessary because the CSRF
> > check inspects
> >        request.POST, and afterwards upload handlers cannot be
> > changed, see documentation
> >        link given below.)
>
> >        The handler is installed as described in the Django
> > documentation "Modifying upload handlers
> >        on the fly", see
>
> >https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#modif...
> >    '''
>
> >    upload_handler = None
>
> >    def dispatch(self, request, *args, **kwargs):
> >        if not self.upload_handler is None:
> >            request.upload_handlers.insert(0,
> > UploadHandlerMixin._instantiate_upload_handler(self.upload_handler,
> > request))
> >        return _uploadhandler_dispatch(request, self, *args, **kwargs)
>
> >    @staticmethod
> >    def _instantiate_upload_handler(path, *args, **kwargs):
> >        i = path.rfind('.')
> >        module, attr = path[:i], path[i+1:]
> >        try:
> >            mod = importlib.import_module(module)
> >        except ImportError, e:
> >            raise ImproperlyConfigured('Error importing upload handler
> > module %s: "%s"' % (module, e))
> >        except ValueError, e:
> >            raise ImproperlyConfigured('Error importing upload handler
> > module. Is FILE_UPLOAD_HANDLERS a correctly defined list or tuple?')
> >        try:
> >            c

Re: Custom upload handler in generic view

2011-10-26 Thread Andre Terra
Are you using nginx by any chance? I use nginx and my setup is as follows:

A upload.py with the custom handler and a view to yield progress result as
json [1], a template with some javascript [2] to fetch the json-formatted
progress result, some lines in nginx.conf [3] to tell it to keep track of
uploads (nginx must be compiled with HttpUploadProgressModule [4]) and a bit
of patience to get it up and running.

I have compiled nginx for windows with that additional module. The
instructions are pretty much gone at this point, but I can zip the binaries
and send it your way should you need them.

You will also notice that I use a /projects/mysite/mysite layout for my
django projects, which is consistent with the new layout in 1.4/trunk [5].

I almost forgot! I'm also using a custom JSONMixin which calls get_data() on
ajax requests in any view that implements it and returns self.data (to be
set by self.get_data) as json [6].

Best of luck!



Cheers,
AT

[1] http://dpaste.com/hold/641334/
[2] http://dpaste.com/hold/641337/
[3] http://dpaste.com/hold/641339/
[4] http://wiki.nginx.org/HttpUploadProgressModule
[5]
https://docs.djangoproject.com/en/dev/intro/tutorial01/#creating-a-project
[6] http://dpaste.com/hold/641344/


On Wed, Oct 26, 2011 at 9:21 AM, hbf  wrote:

> Dear all,
>
> In order to provide progress feedback of file uploads I needed to
> install an upload handler for a specific view. This is documented for
> "classical" views at
>
>
> https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#modifying-upload-handlers-on-the-fly
>
> For generic views, however, I could not find any instructions and I
> came up with the following, which I would like to share:
>
> # BEGIN OF CLASS
> from django.utils import importlib
> from django.core.exceptions import ImproperlyConfigured
> from django.views.decorators.csrf import csrf_protect
>
> class UploadHandlerMixin(object):
>'''
>A mixin for Django generic views that installs a custom upload
> handler in front of
>the current chain of upload handlers.
>
>You specify the handler to install by overriding the
> 'upload_handler' attribute of
>the class, specifying the module and class name in the form
> 'path.to.module.class':
>
>class MyView(UploadHandlerMixin, View):
>upload_handler = 'path.to.module.MyUploadHandler'
>
>If you do not override 'upload_handler', no additional upload
> handler will be
>installed.
>
>If the CsrfViewMiddleware is installed (which is the default)
> then you must use
>your view as follows in your urls.py:
>
>from django.views.decorators.csrf import csrf_exempt
>url(r'^.../$', csrf_exempt(MyView.as_view()), ...),
>
>Internally, the UploadHandlerMixin mixin will install the
> upload handler and then
>perform the CSRF check. (This is necessary because the CSRF
> check inspects
>request.POST, and afterwards upload handlers cannot be
> changed, see documentation
>link given below.)
>
>The handler is installed as described in the Django
> documentation "Modifying upload handlers
>on the fly", see
>
> https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#modifying-upload-handlers-on-the-fly
>'''
>
>upload_handler = None
>
>def dispatch(self, request, *args, **kwargs):
>if not self.upload_handler is None:
>request.upload_handlers.insert(0,
> UploadHandlerMixin._instantiate_upload_handler(self.upload_handler,
> request))
>return _uploadhandler_dispatch(request, self, *args, **kwargs)
>
>@staticmethod
>def _instantiate_upload_handler(path, *args, **kwargs):
>i = path.rfind('.')
>module, attr = path[:i], path[i+1:]
>try:
>mod = importlib.import_module(module)
>except ImportError, e:
>raise ImproperlyConfigured('Error importing upload handler
> module %s: "%s"' % (module, e))
>except ValueError, e:
>raise ImproperlyConfigured('Error importing upload handler
> module. Is FILE_UPLOAD_HANDLERS a correctly defined list or tuple?')
>try:
>cls = getattr(mod, attr)
>except AttributeError:
>raise ImproperlyConfigured('Module "%s" does not define a
> "%s" upload handler backend' % (module, attr))
>return cls(*args, **kwargs)
>
> @csrf_protect
> def _uploadhandler_dispatch(request, view, *args, **kwargs):
>return super(UploadHandlerMixin, view).dispatch(request, *args,
> **kwargs)
> # END OF CLASS
>
> Not being a Django expert, I wanted to ask whether this is okay
> security-wise? Any other feedback is of course welcome.
>
> Best,
> Kaspar
>
> P.S. I opened a question at stackoverflow,
>
>
> http://stackoverflow.com/questions/7901895/how-to-install-a-custom-upload-handler-in-a-django-generic-view
>
> and will keep both this thread and the latter post updated.
>
> --
> You received this message because yo

Custom upload handler in generic view

2011-10-26 Thread hbf
Dear all,

In order to provide progress feedback of file uploads I needed to
install an upload handler for a specific view. This is documented for
"classical" views at

  
https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#modifying-upload-handlers-on-the-fly

For generic views, however, I could not find any instructions and I
came up with the following, which I would like to share:

# BEGIN OF CLASS
from django.utils import importlib
from django.core.exceptions import ImproperlyConfigured
from django.views.decorators.csrf import csrf_protect

class UploadHandlerMixin(object):
'''
A mixin for Django generic views that installs a custom upload
handler in front of
the current chain of upload handlers.

You specify the handler to install by overriding the
'upload_handler' attribute of
the class, specifying the module and class name in the form
'path.to.module.class':

class MyView(UploadHandlerMixin, View):
upload_handler = 'path.to.module.MyUploadHandler'

If you do not override 'upload_handler', no additional upload
handler will be
installed.

If the CsrfViewMiddleware is installed (which is the default)
then you must use
your view as follows in your urls.py:

from django.views.decorators.csrf import csrf_exempt
url(r'^.../$', csrf_exempt(MyView.as_view()), ...),

Internally, the UploadHandlerMixin mixin will install the
upload handler and then
perform the CSRF check. (This is necessary because the CSRF
check inspects
request.POST, and afterwards upload handlers cannot be
changed, see documentation
link given below.)

The handler is installed as described in the Django
documentation "Modifying upload handlers
on the fly", see
https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#modifying-upload-handlers-on-the-fly
'''

upload_handler = None

def dispatch(self, request, *args, **kwargs):
if not self.upload_handler is None:
request.upload_handlers.insert(0,
UploadHandlerMixin._instantiate_upload_handler(self.upload_handler,
request))
return _uploadhandler_dispatch(request, self, *args, **kwargs)

@staticmethod
def _instantiate_upload_handler(path, *args, **kwargs):
i = path.rfind('.')
module, attr = path[:i], path[i+1:]
try:
mod = importlib.import_module(module)
except ImportError, e:
raise ImproperlyConfigured('Error importing upload handler
module %s: "%s"' % (module, e))
except ValueError, e:
raise ImproperlyConfigured('Error importing upload handler
module. Is FILE_UPLOAD_HANDLERS a correctly defined list or tuple?')
try:
cls = getattr(mod, attr)
except AttributeError:
raise ImproperlyConfigured('Module "%s" does not define a
"%s" upload handler backend' % (module, attr))
return cls(*args, **kwargs)

@csrf_protect
def _uploadhandler_dispatch(request, view, *args, **kwargs):
return super(UploadHandlerMixin, view).dispatch(request, *args,
**kwargs)
# END OF CLASS

Not being a Django expert, I wanted to ask whether this is okay
security-wise? Any other feedback is of course welcome.

Best,
Kaspar

P.S. I opened a question at stackoverflow,

  
http://stackoverflow.com/questions/7901895/how-to-install-a-custom-upload-handler-in-a-django-generic-view

and will keep both this thread and the latter post updated.

-- 
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: redirect problems

2011-10-26 Thread sumiir lee
hi, guys,
try it .

 ..
return HttpResponseRedirect(reverse('myAppFront.views.article', None, None,
{'id': id}))

2011/10/25 nicolas HERSOG 

> God you'r right !
>
> Thanks to your answer i found why my "named" url didn't work.
>
> I wrote this in my urls.py :
> (r'^article/(?P\d+)/$', myAppFront.views.article, name='article'),
> instead of :
>*url*(r'^article/(?P\d+)/$', myAppFront.views.article,
> name='article'),
>
> AND, you'r right, i didn't use the name i defined (here 'article') in my
> redirection.
>
> Thx you Tom :)
>
>
> On Mon, Oct 24, 2011 at 5:52 PM, Tom Evans wrote:
>
>> On Mon, Oct 24, 2011 at 12:34 PM, nicolas HERSOG 
>> wrote:
>> > Hi everyone,
>> > I digged more but i'm still stuck.
>> > I understood that i have to use namespaceURL.
>> > So i modified my url.py this way :
>> > from myAppFront.views import article
>> > url (r'^article/(?P\d+)/$',
>> > myAppFront.views.article,
>> > name='article'),
>>
>> Note: this doesn't namespace it, it gives it the explicit name
>> 'article'. If you gave it a name like 'myApp:article' it would be in
>> the myApp namespace, or if the entire urlconf is included in the main
>> urlconf with a namespace, but you don't mention doing that.
>>
>> > and this is my addComment view :
>> > ...
>> > #return HttpResponseRedirect(reverse('myAppFront.views.article',
>> > args=(id,)))
>> > return HttpResponseRedirect(reverse('myAppFront.views.article',
>> > kwargs={'id': id}))
>>
>> Having named it, you can (and should) use the name when reversing the
>> URL, not the view definition, eg:
>>
>>  return HttpResponseRedirect(reverse('article', args=(id,)))
>>
>> You could also use the dict syntax as well, I prefer the tuple version
>> for simple single argument URLs like this.
>>
>> Hope that helps
>>
>> Cheers
>>
>> Tom
>>
>> --
>> 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.
>>
>>
>  --
> 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.
>

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



no return from image_set.all yet code almost identical

2011-10-26 Thread MikeKJ

The problem:
imsettop and imsetbottrom return an image_set.all
headset doesnt, yet the code to get all three are almost identical

can anyone spot the error please?

I have 2 models going through a view to a template

simple models:
model image_sets

from django.db import models
from smartpages.models import SmartPage

POSITIONCHOICES = [
('1', 'Top'),
('2', 'Bottom')
]

class Set(models.Model):
assigned_page = models.ForeignKey(SmartPage, help_text='The smartpage
this set is assigned to')
position = models.CharField(choices=POSITIONCHOICES, max_length=1)
name = models.CharField(max_length=50, help_text='An identifying name,
like the name of the smartpage')

def __unicode__(self):
return self.name

class Image(models.Model):
page = models.ForeignKey(Set)
image = models.ImageField(upload_to='page_sets')

model head_sets

from django.db import models
from smartpages.models import SmartPage

class HeadSet(models.Model):
assigned_page = models.ForeignKey(SmartPage, help_text='The smartpage
this set is assigned to')
name = models.CharField(max_length=50, help_text='An identifying name,
like the name of the smartpage')

def __unicode__(self):
return self.name

class HeadImage(models.Model):
page = models.ForeignKey(HeadSet)
image = models.ImageField(upload_to='head_sets')


View  // sp = the page being delivered

from image_sets.models import Set, Image
from head_sets.models import HeadSet, HeadImage

imsettop =
Set.objects.all().filter(position=1).filter(assigned_page=sp.id)
imsetbottom = Set.objects.all().filter(position=2).filter(assigned_page
= sp.id)
headset = HeadSet.objects.all().filter(assigned_page = sp.id)

Template

{% for x in headset %}
{% for t in x.image_set.all %}
 {{ t.image.url }} 
{% endfor %}
{% endfor %}




{% for i in imsettop %}
{% for x in
i.image_set.all %}

{{x.image.url|thumbnail: 
{% endfor %}
{% endfor %}



{% for y in imsetbottom %}
{% for w in
y.image_set.all %}

{{w.image.url|thumbnail: 
{% endfor %}
{% endfor %}








-- 
View this message in context: 
http://old.nabble.com/no-return-from-image_set.all-yet-code-almost-identical-tp32723239p32723239.html
Sent from the django-users mailing list archive at Nabble.com.

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



queryset extension with field from different model

2011-10-26 Thread ggavy
Hi,
this is just a question to help me understand queryset usage a
little better.

If I had two models, unrelated via foreignkey etc, but which shared a
common field, e.g.

class modelOne(models.Model):
a = 
b = 
c = 

class modelTwo(models.Model):
c = 
d = 
e = 

how can I create a queryset pulling in features of both. That is, if I
had

myqueryset = modelOne.objects.all()

how can I append the d value from modelTwo (having worked out the
matching c values) to myqueryset?

For example, I'm assuming this is not the way I should be doing this:

myqueryset = modelOne.objects.all()
for item in myqueryset:
dvalue = 
item.dvalue = dvalue

Any pointers for how I should be doing this? (noting that I have the
use case for ending up with a single queryset)

Many Thanks,
G


-- 
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: nested forms?!?

2011-10-26 Thread Daniel Roseman
On Tuesday, 25 October 2011 23:56:35 UTC+1, trubliphone wrote:
>
> I am just banging my head against the wall and making no progress with 
> this issue.
>
> I am trying to create a view that nests forms of related models.  I had 
> thought that inlineformset_factory would do the trick, but I clearly 
> don't understand something.
>
> Assume I have the following models:
>
> 
> class Author(models.Model):
>  name = models.CharField(max_length=100)
>
> class Book(models.Model):
>  author = models.ForeignKey(Author)
>  title = models.CharField(max_length=100)
> 
>
> And the following forms:
>
> 
> class AuthorForm(forms.ModelForm):
>  class Meta:
>  model = Author
>
> class BookForm(forms.ModelForm):
>  class Meta:
>  model = Book
>
> BookInlineFormSet = inlineformset_factory(Author, Book)
> 
>
> Now assume I want to create a view that lets me create a new books, 
> along with a new author.  According to various documentation, I ought to 
> do something a bit like this:
>
> 
> def new_author(request):
>authorForm = AuthorForm()
>author = Author() # an empty author
>bookFormSet = BookInlineFormSet(instance=author) # since author is 
> empty, shouldn't this contain empty forms?
>return render_to_response("new_author.html", {"formset" : bookFormSet, 
> })
> 
>
> But all I get is a set of fields belonging to the BookForm ("title") and 
> nothing from the AuthorForm ("name").
>
> Any advice?
>
> Thanks for your help.
>
>
>
You're on the right track with inlineformset, but you still need to render 
the parent form separately - the formset is only the related items, not the 
parent. So just pass `authorForm` to the context and display it as normal 
(with `{{ authorForm.as_p }}` or by iterating through the fields).
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/-ib-7n7o59IJ.
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.



Regression in blocktrans tag parsing between 1.2 and 1.3

2011-10-26 Thread Tom Evans
Hi all

Django 1.3's blocktrans tag is documented as still supporting 1.2's
more verbose syntax. However, if you attempt a plural translation, it
barfs. More importantly, it rejects a format that 1.2 accepts, and
accepts a format that 1.2 rejects.

This format is rejected by 1.2 and accepted by 1.3:

tmpl2 = """
{% load i18n %}
{% blocktrans with items as stuff and count items|length|add:"-3" as
more_count %}
{{ more_count }} more
{% plural %}
{{ more_count }} more
{% endblocktrans %}
"""

This format is accepted by 1.2 and rejected by 1.3:

tmpl3 = """
{% load i18n %}
{% blocktrans count items|length|add:"-3" as more_count and items as stuff %}
{{ more_count }} more
{% plural %}
{{ more_count }} more
{% endblocktrans %}
"""

The 1.3 documentation states that "The previous more verbose format is
still supported", without going into details of what that format is.
This probably requires either a fix to be more 1.2 compatible, or a
documentation note in 1.3 noting the differences in formats that it
will parse and  an update to the 1.3 backwards incompatibilities
noting this difference.

Cheers

Tom


Full transcripts below:

>>> from django.template import Template, Context, TemplateSyntaxError
>>> import django
>>> django.VERSION
(1, 2, 7, 'final', 0)
>>> try:
... Template(tmpl2).render(Context({'items':[1,2,3,4,5,6]}))
... except TemplateSyntaxError, e:
... print e
...
variable bindings in 'blocktrans' must be 'with value as variable'
>>> try:
... Template(tmpl3).render(Context({'items':[1,2,3,4,5,6]}))
... except TemplateSyntaxError, e:
... print e
...
u'\n\n\n3 more\n\n'


>>> from django.template import Template, Context, TemplateSyntaxError
>>> import django
>>> django.VERSION
(1, 3, 1, 'final', 0)
>>> try:
... Template(tmpl2).render(Context({'items':[1,2,3,4,5,6]}))
... except TemplateSyntaxError, e:
... print e
...
u'\n\n\n3 more\n\n'
>>> try:
... Template(tmpl3).render(Context({'items':[1,2,3,4,5,6]}))
... except TemplateSyntaxError, e:
... print e
...
"count" in u'blocktrans' tag expected exactly one keyword argument.

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