dynamic mod wsgi

2008-12-08 Thread ben.dja...@googlemail.com

Hi, I'm converting to the excellent mod_wsgi and wondering if it's
possible to make a single httpd virtual host/wsgi file to manage
wildcard subdomains.

Basically I have an app where i'm creating a new instance for each
client and using subdomains. So client1.example.com and
client2.example.com both point to the same app, but their own
settings.py/django instance.

So far so fine.  I've been happily converting to mod_wsgi daemons,
creating virtual hosts and independent .wsgi files for each one. But
now just wondering whether there is some way i can make this process
dynamic so one virtual host/.wsgi file will take care of all these
subdomains.

I see the advice on the wsgi wiki to push domain sub-directories to
different django instances, but i'd rather keep using the subdomains
if possible.

It looks possible to be able to parse information about the incoming
request in the wsgi file and push it to different settings. But i'm
not sure what this will do in terms of spawning processes etc, it
looks a little dangerous, or maybe this will work. Any advice
appreciated 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Please help me with static files serving

2008-12-08 Thread Jeff Anderson
Oleg Oltar wrote:
> Hi!
>
> I am trying to setup django to use static files for development purposes. 
> I used http://docs.djangoproject.com/en/dev/howto/static-files/
>
> But actually failed to serve anything :(
>
> My urls.py
>
> urlpatterns = patterns('django.views.generic.simple',
>   
> (r'','direct_to_template',{'template':'index.html'}),
>)
> if settings.DEBUG:
> urlpatterns += patterns('',
> (r'^media/(?P.*)$','django.views.static.serve', {'\
> document_root': '/Users/oleg/media/spilka/'}),
>   )
>
> But needed media is not loaded, e.g.
>
> `-- spilka
> |-- css
> |   `-- styles.css
>
> And http://127.0.0.1:8000/media/css/styles.css
> gives Page not found:
> /usr/local/lib/python2.5/site-packages/django/contrib/admin/media/css/styles.css
You've run into a "gotcha" with your MEDIA_URL and ADMIN_MEDIA_PREFIX.
Basically the development server will add the static file view
automatically based on the ADMIN_MEDIA_PREFIX url. This is set to
'/media' so your own media URL is passed, and it is trying to serve the
files from the admin media.

One way to fix this is to change your url from /media to something else,
and leave all the admin media at /media. Usually what I do is change the
ADMIN_MEDIA to something else. '/admin/media' makes sense to me, so
that's usually what I set it to. Some people set their MEDIA_URL url to
something like '/static'. Another logical way to set the URLs is to have
MEDIA_URL be '/media' and ADMIN_MEDIA_PREFIX set to '/media/admin'

Hopefully this is helpful and makes sense!


Jeff Anderson



signature.asc
Description: OpenPGP digital signature


Re: Unit Testing forms with hidden fields

2008-12-08 Thread Jason Sidabras

Sounds good. I will probably work with Twill.

Thanks!

On Dec 8, 10:34 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Mon, 2008-12-08 at 20:16 -0800, Jason Sidabras wrote:
> > Sorry, I guess I missed that part.
>
> > In my template it checks if there is a user logged in or not. If there
> > is not a user, it defaults the hidden field to send_id=1 and has a
> > form to place an email address. If the user is logged in the template
> > uses the pk_id from the user (in the case of non-admin pk=2 and up)
> > and then places the username a hidden field also.
>
> > So when the send button is pushed it sends both the sender_id="2" (or
> > whichever user) and the username="test_userwith_pk2"
>
> > So when I am testing and I have an anonymous user a simple post will
> > work to test my views, but when the user is logged in data comes from
> > the template so just "post" won't do. I would need to simulate
> > clicking the submit button.
>
> > Twill seems to do this similar to Perl's mechanize module. I am
> > familiar with this 'find forum' submit type of coding but I was
> > wondering if django has a way to grab these hidden fields and place
> > them in the post data when i run a
>
> > c = Client()
> > c.post('/contact-us/', {'some': 'variables' [+ hidden variables from
> > template]})
>
> No, Django's test.client.Client is simulating only the HTTP side of
> things. It doesn't parse any HTML. Twill goes partway by parsing the
> HTML, but then if you have modifications made by other purposes (e.g.
> Javascript, it doesn't pick those up). Short of using a web browser (the
> Selenium approach), there isn't an ideal way here.
>
> Probably wouldn't be too hard to write a subclass that did twill-like
> parsing (even using Twill) if you were sufficiently motivated.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Complex lookups and SelectMultiple widget

2008-12-08 Thread issya

Thank you for the reply. I tried going the route of using the below.
Is your way better? Since 'in' needs a list as an argument and
SelectMultiple returns a list:


if request.method == "POST" or request.GET.get('page', ''):
search_form = SearchForm(request.POST)
if search_form.is_valid():
search_clean = search_form.cleaned_data
results = Mls.objects.filter
(county__in=search_clean['county']


On Dec 8, 2:33 am, krylatij <[EMAIL PROTECTED]> wrote:
> > I am working on a search form that has a SelectMultiple widget. What
> > would be the best way to make a complex lookup with the SelectMultiple
> > widget?
>
> try this:
> 
> try:
>     district_ids = [int(x) for x in request.GET.getlist('district')]
>     if len(district_ids) == 0:
>         district_ids = [-1, ]
> except KeyError, ValueError:
>         district_ids = [-1,]
> ...
> if -1 not in district_ids:
>     # search by district
>     return MyModel.objects.filter(district__in = district_ids)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Please help me with static files serving

2008-12-08 Thread Oleg Oltar
Hi!
I am trying to setup django to use static files for development purposes.
I used http://docs.djangoproject.com/en/dev/howto/static-files/

But actually failed to serve anything :(

My urls.py

urlpatterns = patterns('django.views.generic.simple',
   (r'','direct_to_template',{'template':'index.html'}),
   )
if settings.DEBUG:
urlpatterns += patterns('',
(r'^media/(?P.*)$','django.views.static.serve', {'\
document_root': '/Users/oleg/media/spilka/'}),
  )

But needed media is not loaded, e.g.

`-- spilka
|-- css
|   `-- styles.css

And http://127.0.0.1:8000/media/css/styles.css
gives Page not found:
/usr/local/lib/python2.5/site-packages/django/contrib/admin/media/css/styles.css


Thanks,
Oleg

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



OperationalError -- Table has no column named ..

2008-12-08 Thread djan

Hello,

I'm running OpenSuSE-11.0 with the lastest version of django and
sqlite3.
When I enter the admin interface to enter data into my database, I got
the error:

OperationalError at /admin/archive/artist/add/

table archive_artist has no column named salutation

Request Method: POST
Request URL:http://127.0.0.1:8000/admin/archive/artist/add/
Exception Type: OperationalError
Exception Value:table archive_artist has no column named salutation

This error is for the first field of the first table, so I suspect
there is a deeper issue. Perhaps related to this, when I enter the
admin interface, I only see a way to enter records for "Artist", and
not any of the other tables I described below (i.e. "Images",
"Gallery", "On_Loan"). I'm new to database design; perhaps the
relations are off? My models.py looks as follows. Thanks in advance
for any help or suggestions.

class Artist(models.Model):
salutation = models.CharField(max_length=10, blank=True)
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
headshot = models.ImageField(upload_to='/tmp/statement',
blank=True)
statement = models.TextField(blank=True)

def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)

class Images(models.Model):
artist = models.ForeignKey(Artist)
file = models.ImageField(upload_to='/tmp/images')
title = models.CharField(max_length=50)
date = models.DateField()

def __unicode__(self):
return u'%s %s' % (self.title, self.date)

class Gallery(models.Model):
images = models.ForeignKey(Images, blank=True)
videos = models.ForeignKey(Videos, blank=True)
name = models.CharField(max_length=40)
address = models.CharField(max_length=30, blank=True)
city = models.CharField(max_length=60, blank=True)
country = models.CharField(max_length=50, blank=True)
phone = models.CharField(max_length=13, blank=True)
email = models.EmailField(blank=True)
website = models.URLField(blank=True)

def __unicode__(self):
return u'%s' % (self.name)

class On_Loan(models.Model):
artist = models.ForeignKey(Artist)
images = models.ManyToManyField(Images, blank=True)
videos = models.ManyToManyField(Videos, blank=True)
location = models.ForeignKey(Gallery)
expiry = models.DateField()

def __unicode__(self):
return u'%s %s' % (self.location, self.expiry)


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Unit Testing forms with hidden fields

2008-12-08 Thread Malcolm Tredinnick


On Mon, 2008-12-08 at 20:16 -0800, Jason Sidabras wrote:
> Sorry, I guess I missed that part.
> 
> In my template it checks if there is a user logged in or not. If there
> is not a user, it defaults the hidden field to send_id=1 and has a
> form to place an email address. If the user is logged in the template
> uses the pk_id from the user (in the case of non-admin pk=2 and up)
> and then places the username a hidden field also.
> 
> So when the send button is pushed it sends both the sender_id="2" (or
> whichever user) and the username="test_userwith_pk2"
> 
> So when I am testing and I have an anonymous user a simple post will
> work to test my views, but when the user is logged in data comes from
> the template so just "post" won't do. I would need to simulate
> clicking the submit button.
> 
> Twill seems to do this similar to Perl's mechanize module. I am
> familiar with this 'find forum' submit type of coding but I was
> wondering if django has a way to grab these hidden fields and place
> them in the post data when i run a
> 
> c = Client()
> c.post('/contact-us/', {'some': 'variables' [+ hidden variables from
> template]})

No, Django's test.client.Client is simulating only the HTTP side of
things. It doesn't parse any HTML. Twill goes partway by parsing the
HTML, but then if you have modifications made by other purposes (e.g.
Javascript, it doesn't pick those up). Short of using a web browser (the
Selenium approach), there isn't an ideal way here.

Probably wouldn't be too hard to write a subclass that did twill-like
parsing (even using Twill) if you were sufficiently motivated.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bug / missing docs for ModelForms with string ForeignKeys?

2008-12-08 Thread Steven Skoczen

While that makes sense, and I understand the concerns about keeping
documentation focused on highlighting the most common cases, a small
note with the "suspension" information you described near the section
on foreign keys doesn't seem out of place, and would greatly aid
people who might not be the "experienced programmers" you describe.

I've been programming professionally for 12 years, using Django for
past 9 months, and this wasn't clear to me.  Maybe that's worth
something, maybe it's not.  I'd suspect (and hope) that Django is used
by more than people who are expert Django programmers, and helping
people just learning it to avoid common snags (and become "experienced
programmers") would be useful.

As far as behavior, it's still not necessarily intuitive.  The same
"suspension" done on the string foreign keys could also be done for
forms that depend on them.  Stating that that's now how things work
doesn't have any effect on whether or not that's how they *should*
work.


In any case, if the consensus of the group is that this really isn't
worth doing anything about, I'll shut up and hope google can index
this to help the people who run into it in the future.

Thanks for listening,

-Steven



On Dec 8, 7:41 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> This is really one of those cases where the documentation doesn't (and
> probably shouldn't attempt to) address every possible alternative
> version of code layout.
>
> On a technical level, this won't work because the "string" version of
> foreign keys need to do something after the second model has been
> created -- it kind of suspends finishing up the internals of some of hte
> first model's data structures until the second model is finished. So you
> can't use the first model until that point.
>
> On a more pragmatic level, this isn't really an issue. Declaring forms
> in the same file as models is not a particularly sustainable programming
> style. They have different roles to play (one is storage level, the
> other is presentational) and although you may think "I'll only ever have
> one form related to this model", that will turn out not to be the case
> more often than you suspect.
>
> So, yes, the documentation doesn't address this. Whether it's worth
> doing so (thereby making the docs longer to avoid something that is
> going to be fairly unnatural to most experienced programmers anyway), is
> a separate issue. The problem with addressing every single point on that
> level is, of course, that the documentation becomes much, much longer
> and the really important content is lost in the sea of small stuff.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Unit Testing forms with hidden fields

2008-12-08 Thread Jason Sidabras

Sorry, I guess I missed that part.

In my template it checks if there is a user logged in or not. If there
is not a user, it defaults the hidden field to send_id=1 and has a
form to place an email address. If the user is logged in the template
uses the pk_id from the user (in the case of non-admin pk=2 and up)
and then places the username a hidden field also.

So when the send button is pushed it sends both the sender_id="2" (or
whichever user) and the username="test_userwith_pk2"

So when I am testing and I have an anonymous user a simple post will
work to test my views, but when the user is logged in data comes from
the template so just "post" won't do. I would need to simulate
clicking the submit button.

Twill seems to do this similar to Perl's mechanize module. I am
familiar with this 'find forum' submit type of coding but I was
wondering if django has a way to grab these hidden fields and place
them in the post data when i run a

c = Client()
c.post('/contact-us/', {'some': 'variables' [+ hidden variables from
template]})

Thanks.

Jason

On Dec 8, 6:54 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Mon, 2008-12-08 at 15:00 -0800, Jason Sidabras wrote:
> > Hello,
>
> > I am working on adding unit testing to my code and the snag I have
> > come across is in regards to unit fields.
>
> > When user.is_anonymous() I have a hidden field sender_id = 1 which is
> > easy to test by:
>
> > from django.test.client import Client
>
> > c = Client()
> > c.post('sender_id': '1', 'post', '')
>
> > but when setting up unit tests for the form when a user is logged in,
> > I am not clear on how to use the hidden fields.
>
> What do you mean by "how to use"? Hidden fields are just form variables.
> The 'hidden' designation is only relevant for a web browser displaying
> the data. You just submit values normally in your tests.
>
> Could you explain what you are getting stuck on here? How does the
> logged in situation differ from the non-logged-in case?
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bug / missing docs for ModelForms with string ForeignKeys?

2008-12-08 Thread Malcolm Tredinnick


On Mon, 2008-12-08 at 17:46 -0800, Steven Skoczen wrote:
> Hi everyone,
> 
> Have run into either a bug or a lack of documentation, and wanted to
> see the consensus here before posting a ticket.
> 
> When using a Model with an string foreign key (ie. for a second model
> that appears after the referencing model), there's no way to make a
> modelform work if it's placed before the second model.
> 
> For example,
> 
> from django.db import models
> from django.forms import ModelForm
> 
> class Foo(models.Model):
>   bars = models.ForeignKey('Bar')
> 
> class FooForm(ModelForm):
>   class Meta:
>   model = Foo
> 
> class Bar(models.Model):
>   ibbity = models.CharField(max_length=255)
> 
> Will error with "AttributeError: 'str' object has no attribute
> '_meta'"
> 
> 
> However, this will work perfectly fine:
> 
> class Foo(models.Model):
>   bars = models.ForeignKey('Bar')
> 
> class Bar(models.Model):
>   ibbity = models.CharField(max_length=255)
> 
> class FooForm(ModelForm):
>   class Meta:
>   model = Foo
> 
> 
> 
> Why this doesn't work makes sense to me, but it seems like it's either
> missing in the docs (I couldn't find anything on this effect), or a
> bug (if abstracted keys are ok for Foo, that ok should carry over to
> FooForm).
> 
> Thoughts?

This is really one of those cases where the documentation doesn't (and
probably shouldn't attempt to) address every possible alternative
version of code layout.

On a technical level, this won't work because the "string" version of
foreign keys need to do something after the second model has been
created -- it kind of suspends finishing up the internals of some of hte
first model's data structures until the second model is finished. So you
can't use the first model until that point.

On a more pragmatic level, this isn't really an issue. Declaring forms
in the same file as models is not a particularly sustainable programming
style. They have different roles to play (one is storage level, the
other is presentational) and although you may think "I'll only ever have
one form related to this model", that will turn out not to be the case
more often than you suspect.

So, yes, the documentation doesn't address this. Whether it's worth
doing so (thereby making the docs longer to avoid something that is
going to be fairly unnatural to most experienced programmers anyway), is
a separate issue. The problem with addressing every single point on that
level is, of course, that the documentation becomes much, much longer
and the really important content is lost in the sea of small stuff.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: modelformset_factory error: (Hidden field id) with this None already exists.

2008-12-08 Thread Karen Tracey
On Mon, Dec 8, 2008 at 12:52 PM, cyberjack <[EMAIL PROTECTED]> wrote:

>
> Thanks for the idea Karen,
>
>  What's the right mechanism for passing the queryset back into the
> form? I don't see an example in the docs.
>

Just pass the queryset= parm into formset creation during post as you do
during GET:

formset = ReportFormSet(request.POST, request.FILES, queryset=reports)

As I mentioned in ticket #9758, I do not know if this is really what's
intended to be required when using model formsets, but it is a way to make
the post data get matched up properly with existing DB instances.

Karen










>
> Thanks!
>
> -Josh
>
> On Dec 4, 4:10 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> > On Thu, Dec 4, 2008 at 2:12 AM, cyberjack <[EMAIL PROTECTED]> wrote:
> >
> > > Hi,
> >
> > >  I haven't been able to solve this problem, but have made some
> > > progress:
> >
> > > It's definitely *not* bug 9039. I've download the tests from that
> > > ticket and confirmed the fix was included in 1.0.2 final.
> >
> > > The problem is related to using querysets with formset_factory.  Ie,
> > > if I include a queryset filter, then I see this error. If I don't
> > > include a queryset, and thus edit all status reports, I don't see the
> > > error.
> >
> > > Lastly, I've simplified my code producing the problem:
> >
> > > my model:
> >
> > > class StatusReport(models.Model):
> > >   vehicle   = models.IntegerField()
> > >   report_date   = models.DateField()
> > >   status= models.CharField(max_length=10)
> >
> > > and my view:
> >
> > > def detail(request, vehicle_id):
> > >limited_reports = StatusReport.objects.filter(vehicle=vehicle_id)
> >
> > >StatusFormSet = modelformset_factory(StatusReport, extra=0)
> > >if request.method == 'POST':
> > >formset = StatusFormSet(request.POST)
> > > if formset.is_valid():
> > >formset.save()
> > > else:
> > ># with error
> > >#formset = StatusFormSet(queryset=limited_reports)
> > ># without error
> > >formset = StatusFormSet()
> > >return render_to_response('manage_articles.html',
> > >  {'formset': formset,
> > >   'vehicle_id': vehicle_id})
> >
> > > Is this a bug in Django? If so, what should I include in the bug
> > > report?
> >
> > I think the bug is that you need to pass the queryset parameter when you
> are
> > dealing with a POST (if you've specified it on the GET) so that the
> posted
> > data can be matched up to the existing model instances.  Otherwise I
> think
> > it will be trying to validate and save as all new instances, and I think
> the
> > error message is saying you wind up with duplicate primary key ids when
> you
> > try that (though I will say that error message might could use some
> > improvement).
> >
> > Karen
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Bug / missing docs for ModelForms with string ForeignKeys?

2008-12-08 Thread Steven Skoczen

Hi everyone,

Have run into either a bug or a lack of documentation, and wanted to
see the consensus here before posting a ticket.

When using a Model with an string foreign key (ie. for a second model
that appears after the referencing model), there's no way to make a
modelform work if it's placed before the second model.

For example,

from django.db import models
from django.forms import ModelForm

class Foo(models.Model):
bars = models.ForeignKey('Bar')

class FooForm(ModelForm):
class Meta:
model = Foo

class Bar(models.Model):
ibbity = models.CharField(max_length=255)

Will error with "AttributeError: 'str' object has no attribute
'_meta'"


However, this will work perfectly fine:

class Foo(models.Model):
bars = models.ForeignKey('Bar')

class Bar(models.Model):
ibbity = models.CharField(max_length=255)

class FooForm(ModelForm):
class Meta:
model = Foo



Why this doesn't work makes sense to me, but it seems like it's either
missing in the docs (I couldn't find anything on this effect), or a
bug (if abstracted keys are ok for Foo, that ok should carry over to
FooForm).

Thoughts?

Thanks,
Steven


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: User in form wizard

2008-12-08 Thread Nathaniel Whiteinge

On Dec 8, 8:00Â am, chewynougat <[EMAIL PROTECTED]>
wrote:
> Could anyone tell me if I can pass the current user to a form wizard
> step so I can prepopulate their object details in the form? If so,
> how?

It depends on where exactly you need to access the current user. If
you can do it *after* form validation has been completed and just use
``commit=False`` [1] when saving the form to fill in the extra data,
that's easily accomplished in the ``done()`` method of the form [2].

However, if you need the current user right when the form is
instantiated (if you need a pre-populated form to edit an existing
object, for example) you're in for a bit of extra work. Here's a
FormWizard class that I use to pass the ``instance`` [1] keyword to
all the ModelForms in a Wizard. (Obviously you'll need to do a bit of
extra leg-work if all of your forms don't derive from the same model,
or aren't ModelForms at all.)::

class YourFormWizard(FormWizard):
def __call__(self, request, *args, **kwargs):
"""Override for getting instance to get_form."""
self.instance = kwargs.pop('instance', None)
return super(YourFormWizard, self).__call__(
request, *args, **kwargs)

def get_form(self, step, data=None):
"""Override for passing the instance keyword argument."""
# If all your ModelForms aren't of the same model you'll
# need to do an isinstance() check, or something similar
to
# only pass the instance keyword to the right form.
return self.form_list[step](
data,
prefix=self.prefix_for_step(step),
initial=self.initial.get(step, None),
instance=self.instance)

Use like so::

def some_edit_view(request, some_id):
instance = get_object_or_4o4(
YourModel, user=request.user, id=some_id)
return YourFormWizard([YourForm1, YourForm2])(
request, instance=instance)

If that's more confusing than helpful, post your code and I'll give
you a more specific example. :)

- whiteinge


.. [1] 
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method
.. [2] 
http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/#creating-a-formwizard-class
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Unit Testing forms with hidden fields

2008-12-08 Thread Malcolm Tredinnick


On Mon, 2008-12-08 at 15:00 -0800, Jason Sidabras wrote:
> Hello,
> 
> I am working on adding unit testing to my code and the snag I have
> come across is in regards to unit fields.
> 
> When user.is_anonymous() I have a hidden field sender_id = 1 which is
> easy to test by:
> 
> from django.test.client import Client
> 
> c = Client()
> c.post('sender_id': '1', 'post', '')
> 
> but when setting up unit tests for the form when a user is logged in,
> I am not clear on how to use the hidden fields.

What do you mean by "how to use"? Hidden fields are just form variables.
The 'hidden' designation is only relevant for a web browser displaying
the data. You just submit values normally in your tests.

Could you explain what you are getting stuck on here? How does the
logged in situation differ from the non-logged-in case?

Regards,
Malcolm



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: i18n and l10n of templates for emails

2008-12-08 Thread Malcolm Tredinnick


On Mon, 2008-12-08 at 07:11 -0800, Kresimir Tonkovic wrote:
> Hi!
> 
> I'm using templetes to generate the HTML body for some reports I send
> daily by email. I do it like this:
> 
> context = Context()
> context["some_var"] = some_value
> 
> 
> resp = render_to_string("daily_report.html", context)
> 
> msg = EmailMultiAlternatives(
> _(u'Daily report'), _('Please use a html-emabled mail
> reader'),
> _('[EMAIL PROTECTED]'), ['[EMAIL PROTECTED]'])
> msg.attach_alternative(resp, "text/html")
> msg.send()
> 
> The template is i18n-ized and is actually created from a page template
> that works correctly. But these reports are never translated to the
> langauge set in settings.py LANGUAGE_CODE, nor have I found any other
> way to control i18n of this template's rendering. I guess this has to
> do with me using Context instead of RequestContext. Obviously there is
> no request here and thus no RequestContext.
> 
> Any ideas how I could control 18n in this scenario?

Look at what the LocaleMiddleware does for a clue.

The "active" locale, which is stored in the per-thread environment is
what is used when rendering. So it has to be set somehow.

from django.utils import translation

translation.activate(language)

Regards,
Malcolm



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



custom distinct() method

2008-12-08 Thread jamesjacksonn...@gmail.com

Here comes the question about the proper usage of queryset's distinct
() method. As i have a queryset model.objects.filter
(column='name').distinct() , the distinct method is applied to whole
objects, but i'd like it to be applied to column. Django makes SQL
query "SELECT DISTINCT column, column2, column3 from TABLE WHERE
'column'='name'. How could i tell django to make querie SELECT
DISTINCT column from TABLE WHERE 'column'='name' so that the
comparison would be made for the single attribute , not for whole
objects. As i guess performing such filtering in SQL server is much
resource-savy than in view level, or template level of django. thanks
for any ideas!

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: time it takes django to read database?

2008-12-08 Thread Jay Parlar

Could you post your urls.py file for your blog app? It's very easy to
make a mistake in there that results in confusing time-related errors.

Jay P.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Development server crash with no error message

2008-12-08 Thread Graham Dumpleton



On Dec 9, 8:50 am, Andrew Fong <[EMAIL PROTECTED]> wrote:
> When I'm poking around in my Django app, my development server
> (manage.py runserver) will sometimes quit without raising an exception
> or leaving any messages. I am not tinkering around with the code or
> doing anything that would force a reload. It just decides to quit.
>
> I can check the last request I made before it crashed, but without any
> exceptions or errors, it's very hard to debug. Does anyone have any
> tips on getting some more useful output out of a crash?

What database adapter are you using? Is it a current version?

What other third party packages are you using which use a C extension
module to do stuff?

Graham
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: range-like template tag?

2008-12-08 Thread Berco Beute

Ah! Of course, why didn't I think of that! Works like a charm.

Thx!
2B

On Dec 8, 7:23 pm, Adi Sieker <[EMAIL PROTECTED]> wrote:
> Couldn't you add a method get_range() (or whatever name makes sense in  
> your context)
> to the class the object is an instqnce of.
> The method would look something like this:
>      def get_range(self):
>          return range(self.someInt)
>
> in your template you could then do:
>      {% for i in object.get_range %}
>
> adi
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: No module named urls

2008-12-08 Thread TheIvIaxx

Ok, i got it all sorted out.  Thanks Rob and Malcom.  It was a problem
in my  accounts.urls.py file.  I had made some placeholder urls to
edit and save but never put them into the view.py.  I commented them
out for now and it worked like a champ.

Its wierd this never poped up in my windows box useing manage.py
runserver, but off the linux box it freaked out.

Thanks again!
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Development server crash with no error message

2008-12-08 Thread Andrew Fong

When I'm poking around in my Django app, my development server
(manage.py runserver) will sometimes quit without raising an exception
or leaving any messages. I am not tinkering around with the code or
doing anything that would force a reload. It just decides to quit.

I can check the last request I made before it crashed, but without any
exceptions or errors, it's very hard to debug. Does anyone have any
tips on getting some more useful output out of a crash?

-- Andrew
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Displaying image stored in models.ImageField

2008-12-08 Thread Craig Spry

Hello All,

I fixed my problem I needed to add a line like this to urls.py:
(r'^uploads/(?P.*)$', 'django.views.static.serve', {
'document_root': 'c:/src/webcomic/uploads' } )

Thanks,
Craig Spry

On Mon, Dec 8, 2008 at 10:49 PM, Craig Spry <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> Just to add to what I've said below, when I point the browser at the
> image url like this:
> http://localhost:8000/uploads/comics/john7_web.png
>
> I get a 404.
>
> Craig
>
> On Mon, Dec 8, 2008 at 10:34 PM, Craig Spry <[EMAIL PROTECTED]> wrote:
>> Hello All,
>>
>> I have an image stored in a models.ImageField that looks like this:
>> comic = models.ImageField(upload_to='comics')
>>
>> and I have this in the settings.py
>> MEDIA_URL = 'http://localhost:8000/uploads/'
>>
>> and in the template I have this:
>> 
>>
>> And all I see in the rendered page is the comic.name.  Is there
>> anything else I need to setup for this to work?
>>
>> Thanks,
>> Craig Spry
>>
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: time it takes django to read database?

2008-12-08 Thread garagefan

I've not set anything up...

On Dec 8, 1:48 am, "Alex Koshelev" <[EMAIL PROTECTED]> wrote:
> Do you use caching?
>
> On Mon, Dec 8, 2008 at 07:34, garagefan <[EMAIL PROTECTED]> wrote:
>
> > ok... i've been able to figure out how long it takes based on the time
> > stamp... an hour and a half for a new object to have come in. It
> > appears that the item is not readable by the two templates, one of
> > which using {%for object in latest $} and then another template that
> > doesn't use it at all.
>
> > the code that reads the objects instantly is:
>
> >  {% for obj in recent_posts %}
> >                                        
> >                                                
> > {{ obj.title}}
> >                                        
> >                                {% endfor %}
>
> > which is getting the info from:
>
> > from django.template import Library, Node
> > from django.db.models import get_model
>
> > register = Library()
>
> > class LatestContentNode(Node):
> >    def __init__(self, model, num, varname):
> >        self.num, self.varname = num, varname
> >        self.model = get_model(*model.split('.'))
>
> >    def render(self, context):
> >        context[self.varname] = self.model._default_manager.filter
> > (status=1)[:self.num]
> >        return ''
>
> > def get_latest(parser, token):
> >    bits = token.contents.split()
> >    if len(bits) != 5:
> >        raise TemplateSyntaxError, "get_latest tag takes exactly four
> > arguments"
> >    if bits[3] != 'as':
> >        raise TemplateSyntaxError, "third argument to get_latest tag
> > must be 'as'"
> >    return LatestContentNode(bits[1], bits[2], bits[4])
>
> > get_latest = register.tag(get_latest)
>
> > an hour and a half is a bit much... i could deal with 5-10 minutes,
> > but at the same time, if the "Recent entries" list reads
> > immediately... so should the rest of the site
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Many to Many entries being duplicated, any ideas?

2008-12-08 Thread Darthmahon

Hi Guys,

I've got a model that has a Many to Many relationship on one of the
fields. This relationship is basically on itself though like this:

#

class UserProfile(models.Model):

user= models.ForeignKey(User, unique=True)
friends_new = models.ManyToManyField('UserProfile', blank=True,
related_name='friend_set_new')

#

I'm trying to "add" to the friends_new field using this code:

#

# get users
initiator_profile = UserProfile.objects.get(user=request.user.id)
recipient_profile = UserProfile.objects.get(user=username)

# now add them as a friend
initiator_profile.friends_new.add(recipient_profile)

#

Now the problem I'm having is that it is adding the friendship to BOTH
userprofiles, initiator and recipient. And when I try to remove the
relationship, again it removes BOTH. So in the database it has two
entries when I only expect there to be one.

Hope I've made that clear enough, any ideas how to get around this?

Cheers,
Chris
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: running template filters after the page has loaded.

2008-12-08 Thread R. Gorman

You're likely going to need to need to run to urlencode function
within the view that processes your ajax request.  Should be able to
import using 'from urllib import urlencode' and then 'urlencode(*your
string variable*)'.

R.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



GeoDjango Server-side Clustering

2008-12-08 Thread Alfonso

Anyone know of an straightforward way to cluster co-ordinate points
server-side i.e. in geoDjango prior to being displayed on an
openlayers map via a standard KML?  At the moment I'm loading some
2000 coordinates from a KML generated by geoDjango but this is quite
understandably slowing the performance even with some OpenLayers
clustering magic!

Thanks,

Allan
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



running template filters after the page has loaded.

2008-12-08 Thread tod

I have an ajax-style update to a page that inserts html into the page
after it has already loaded (and run template filters, etc).  Is there
a way to have the template filters run on the inserted html.

Here are the specifics:  A list of folders is displayed upon the
initial load of the page. Each of the folders contains items that can
be tagged (using django-tagging of course).  If you want to see the
tags for the items in a particular folder you click the link, the ajax
request is fired, and a list of tags is returned. My specific
challenge is that the tags are returned as links.  For single word
tags your get http://site.com/path/to/tag/.  If you have a multi-word
tag such as "django 1.0" you would get: http://site.com/path/to/django
1.0 which isn't a valid url. I want to be able to run the template
filter "urlencode" to convert the tag but, alas the page has already
loaded.

Would love a pointer or two to resolve. Google searches have not
returned any usable results.

Thx.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: i18n and l10n of templates for emails

2008-12-08 Thread Kresimir Tonkovic

On 8 pro, 18:16, "R. Gorman" <[EMAIL PROTECTED]> wrote:
> I ran into the same issue, but different encoding.  I found that
> adding a special comment line to the beginning of the python file
> allowed for the desired encoding (source: 2.2.3 
> fromhttp://www.python.org/doc/2.5.2/tut/node4.html).
>
> Hope that helps,

Thanks R, but this has nothing to do with python code character set.
It's all about template translations.

Regards,
Krešimir
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Training

2008-12-08 Thread Milan Andric

On Mon, Dec 8, 2008 at 10:39 AM, Roland van Laar <[EMAIL PROTECTED]> wrote:
>
> Steve Holden wrote:
>> I am looking at expanding our training offerings for the coming year,
>> and a short course in Django looks like it might be popular. There
>> don't seem to be many Django classes at the moment, and several of the
>> students from our introductory Python classes expressed interest in
>> Django.
>>
>> Without wanting anyone on the list to do my work for me, it would be
>> useful to see some opinions about what to include. The tutorial gives
>> people a good start: should we assume that anyone who wants to take
>> the class has already run through that, or would it be better to start
>> from scratch?

I have successfully taught a one day workshop based on the Django
tutorial/from scratch. I wouldn't want people agonizing on their own
if they are going to take a class.  That's one main reason people take
classes, to save time and energy by having an expert guide them.

Even as I was teaching the tutorial  I found I needed to chop it up
because it was too long for total newbies.  I like teaching from the
tutorial because when people want to go back and learn they know
exactly where to go and can continue where they left off or dive in
deeper on specific areas they are interested in.

I've been wanting to do a screencast based on the tutorial or mainly
the part without the admin customizations.  Just the MVC (err, MTV)
concepts well done and completed using the poll app as the example,
similar to the tutorial.  And then a second screencast on the admin
contrib app.  This is enough to fill a one or two day workshop for
people completely new to Django.

The screencasts and official Django tutorial would be the learning
companions for the workshop/class. The class would allow people the
freedom to ask questions/share knowledge and stay focused while
getting loaded up with  condensed/organized information.

--
Milan

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to import DoesNotExist exception ???

2008-12-08 Thread Info Cascade

I just want to catch the exception thrown when the query returns nothing.
Thanks, that seems to have done the trick.

[EMAIL PROTECTED] wrote:
> I'm not sure where you got that code snippet from, but DoesNotExist is
> an attribute on model classes, so that shoul read:
>
> except Tag.DoesNotExist.
>
> On Dec 8, 2:52 pm, Info Cascade <[EMAIL PROTECTED]> wrote:
>   
>> How do I import the DoesNotExist exception?
>>
>> This doesn't seem to work:> from django.db.models.query import DoesNotExist
>> 
>>> try:
>>> tag = Tag.objects.get(name=cat_name)
>>> except DoesNotExist:
>>> # do something else
>>>   
>> Doesn't DoesNotExist exist?
>> 
> >
>
>   


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: selected ModelMultipleChoiceField

2008-12-08 Thread Håkan Waara

Yes, that's what my reply to you was about. The below examples work  
for ModelChoiceField, you only need to use the same technique on a  
ModelMultipleChoiceField, where I - like I wrote - guess you can use a  
tuple of initial values, e.g. ("foo", "bar").

/Håkan

8 dec 2008 kl. 18.30 skrev Abdel Bolanos Martinez:

> what I want is use ModelMultipleChoiceField with a queryset but I  
> need that some of the  of the  generated be mareked  
> as 

Re: How to import DoesNotExist exception ???

2008-12-08 Thread [EMAIL PROTECTED]

I'm not sure where you got that code snippet from, but DoesNotExist is
an attribute on model classes, so that shoul read:

except Tag.DoesNotExist.

On Dec 8, 2:52 pm, Info Cascade <[EMAIL PROTECTED]> wrote:
> How do I import the DoesNotExist exception?
>
> This doesn't seem to work:> from django.db.models.query import DoesNotExist
> > try:
> >     tag = Tag.objects.get(name=cat_name)
> > except DoesNotExist:
> >     # do something else
>
> Doesn't DoesNotExist exist?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: range-like template tag?

2008-12-08 Thread Adi Sieker

Hi,

On 08.12.2008, at 17:30, Berco Beute wrote:

>
> The 'someInt' is an attribute of an object I pass to the template. It
> varies with each object. I could of course make a dictionary with the
> object and a list of the integers but it would be handy to solve it in
> the template (although you may argue that such functionality should
> stay out of the view)

Couldn't you add a method get_range() (or whatever name makes sense in  
your context)
to the class the object is an instqnce of.
The method would look something like this:
 def get_range(self):
 return range(self.someInt)

in your template you could then do:
 {% for i in object.get_range %}


adi

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: templates database access

2008-12-08 Thread maeck

Your user will not have access to your database from the browser, so
you cannot do any kind of create, update and deletes from templates
directly.
It will always have to go through POST on your views. You could do
some AJAX to avoid web-page roundtrips, but then again, you will be
using views to do this. Never your template.

maeck

On Dec 8, 2:25 am, Vicky <[EMAIL PROTECTED]> wrote:
> Is there any way to insert, retrieve, delete and update tables in a
> database from templates itself?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Reducing the number of my view's database queries

2008-12-08 Thread maeck

I think you are on something here.
Below is what concerns me most in the example:

data[o.name].append(o.model3_set.all().order_by('created')[0])

This will sort the entire model3 table just to get the min value.
And if the db is doing this 6000 times, that is a bit useless.

Have you tried using raw SQL in you model?
See: http://docs.djangoproject.com/en/dev/topics/db/sql/#topics-db-sql
You do not have to use the Django ORM for this.

Maeck


On Dec 8, 7:43 am, DavidA <[EMAIL PROTECTED]> wrote:
> If I undestand the problem correctly, in MySQL you could do this in
> one query as:
>
> select
>     m.*,
>     (select min(created) from model2 where id = m.model2_id) as
> first_created,
>     (select max(created) from model2 where id = m.model2_id) as
> last_created
> from model1 m
> ;
>
> I don't know how that translates to the Django ORM (or even if it
> does), though.
>
> -Dave
>
> On Dec 8, 12:27 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
>
> > On Sat, 2008-12-06 at 20:56 -0800, erikcw wrote:
> > > Hi all,
>
> > > I'm trying to write a model query that will return a queryset along
> > > with the latest (and earliest) data from 2 related models.
>
> > > Right now I'm doing something like this:
>
> > > objects = Model1.objects.filter(user=3).select_related() #about 6,000
> > > objects
>
> > > data = {}
> > > for o in objects:
> > >     data[o.name] = [o.field1, o.field2]
> > >     data[o.name].append(o.field3.model2_set.all().latest('created'))
> > > #get latest row from related model2
> > >     data[o.name].append(o.model3_set.all().order_by('created')[0])
> > > #get earliest row from related model3
>
> > > The problem is that this results in a TON of database queries.  This
> > > view is taking over a minute to process.  The select_related on the
> > > first line doesn't seem to be helping since I'm using latest()/
> > > order_by which generates a new query.
>
> > > How can I make this more efficient?  Denormalizing the isn't an option
> > > since model2 and model 3 are many-to-one.
>
> > By the way (since I still haven't worked out the complex SQL to make it
> > three queries yet), this last statement isn't correct. Denormalising
> > doesn't just mean flattening. You can store a computed dependent field
> > in model1 for the related information. So you could, for example, store
> > the relevant date and pk value of the related model2 row and update that
> > whenever a new model2 is inserted.
>
> > Malcolm
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: modelformset_factory error: (Hidden field id) with this None already exists.

2008-12-08 Thread cyberjack

Thanks for the idea Karen,

 What's the right mechanism for passing the queryset back into the
form? I don't see an example in the docs.

Thanks!

-Josh

On Dec 4, 4:10 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Thu, Dec 4, 2008 at 2:12 AM, cyberjack <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> >  I haven't been able to solve this problem, but have made some
> > progress:
>
> > It's definitely *not* bug 9039. I've download the tests from that
> > ticket and confirmed the fix was included in 1.0.2 final.
>
> > The problem is related to using querysets with formset_factory.  Ie,
> > if I include a queryset filter, then I see this error. If I don't
> > include a queryset, and thus edit all status reports, I don't see the
> > error.
>
> > Lastly, I've simplified my code producing the problem:
>
> > my model:
>
> > class StatusReport(models.Model):
> >   vehicle       = models.IntegerField()
> >   report_date   = models.DateField()
> >   status        = models.CharField(max_length=10)
>
> > and my view:
>
> > def detail(request, vehicle_id):
> >    limited_reports = StatusReport.objects.filter(vehicle=vehicle_id)
>
> >    StatusFormSet = modelformset_factory(StatusReport, extra=0)
> >    if request.method == 'POST':
> >        formset = StatusFormSet(request.POST)
> >         if formset.is_valid():
> >            formset.save()
> >     else:
> >        # with error
> >        #formset = StatusFormSet(queryset=limited_reports)
> >        # without error
> >        formset = StatusFormSet()
> >    return render_to_response('manage_articles.html',
> >                              {'formset': formset,
> >                               'vehicle_id': vehicle_id})
>
> > Is this a bug in Django? If so, what should I include in the bug
> > report?
>
> I think the bug is that you need to pass the queryset parameter when you are
> dealing with a POST (if you've specified it on the GET) so that the posted
> data can be matched up to the existing model instances.  Otherwise I think
> it will be trying to validate and save as all new instances, and I think the
> error message is saying you wind up with duplicate primary key ids when you
> try that (though I will say that error message might could use some
> improvement).
>
> Karen
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: selected ModelMultipleChoiceField

2008-12-08 Thread Abdel Bolanos Martinez
what I want is use ModelMultipleChoiceField with a queryset but I need
that some of the  of the  generated be mareked as

Re: i18n and l10n of templates for emails

2008-12-08 Thread R. Gorman

I ran into the same issue, but different encoding.  I found that
adding a special comment line to the beginning of the python file
allowed for the desired encoding (source: 2.2.3 from
http://www.python.org/doc/2.5.2/tut/node4.html).

Hope that helps,

R.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Training

2008-12-08 Thread Roland van Laar

Steve Holden wrote:
> I am looking at expanding our training offerings for the coming year,
> and a short course in Django looks like it might be popular. There
> don't seem to be many Django classes at the moment, and several of the
> students from our introductory Python classes expressed interest in
> Django.
>
> Without wanting anyone on the list to do my work for me, it would be
> useful to see some opinions about what to include. The tutorial gives
> people a good start: should we assume that anyone who wants to take
> the class has already run through that, or would it be better to start
> from scratch?
>
> Django is such a rich platform it would be possible to write several
> classes: what material do readers regard as the "essentials of
> Django", 
Essential: models, admin, template language, direct_to_template, foreign 
keys, authentication, forms


> and what should be relegated to more advanced classes? 
Advanced: templatetags, signals, model manager, classbased views, 
userprofile

> What
> can I do to put a compelling introductory class together?
>   

Let them write a blog ;-)

Roland
> regards
>  Steve
> >
>   


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: selected ModelMultipleChoiceField

2008-12-08 Thread Håkan Waara

If you want to set it to always the same values, you can use the  
"initial" argument on your form field.

Pseudo-example (haven't run the code, but it illustrates the solution):

class MyForm(forms.Form):
 end = forms.DateField(label="Until", required=False,  
initial="2009-11-12")


If you need to do it dynamically, for some reason. E.g, you don't know  
until you create the form, you can override the form's __init__ and  
set it there.

class MyForm(forms.Form):
 end = forms.DateField(label="Until", required=False)

 def __init__(self, *args, **kwargs):
 super(MyForm, self).__init__(*args, **kwargs)
 self.fields['end'].initial = bar

This works for fields with one value. For multiple preselected values,  
I don't know, but my first hunch would be to try to use a tuple/list  
with initial values instead.

HTH,
/Håkan

8 dec 2008 kl. 17.16 skrev Abdel Bolanos Martinez:

>
> Hi,
> i'm new in django and i'm using ModelMultipleChoiceField and all  
> works fine but i need to 'mark' o 'selected' some model objects from  
> the queryset
>
> have ever someone did something like that???
>
>
> Abdel Bolaños Martínez
> Ing. Infórmatico
> Telf. 266-8562
> 5to piso, oficina 526, Edificio Beijing, Miramar Trade Center. ETECSA
>
> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



no atribute instance in ModelMultipleChoiceField

2008-12-08 Thread Abdel Bolanos Martinez
Why ModelMultipleChoiceField has no atribute 'instance'?

how can I select options in a ModelMultipleChoiceField




Abdel Bolaños Martínez
Ing. Infórmatico
Telf. 266-8562
5to piso, oficina 526, Edificio Beijing, Miramar Trade Center. ETECSA

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: range-like template tag?

2008-12-08 Thread Berco Beute

The 'someInt' is an attribute of an object I pass to the template. It
varies with each object. I could of course make a dictionary with the
object and a list of the integers but it would be handy to solve it in
the template (although you may argue that such functionality should
stay out of the view)

2B

On Dec 8, 5:14 am, Jeff FW <[EMAIL PROTECTED]> wrote:
> You could write a very simple filter to do this.  Something like
> (untested):
>
> def range(top):
>     return xrange(0, top)
>
> then use {% for i in someInt|range %}
>
> I think it would still be better to pass it in the context--why can't
> you do that?
>
> -Jeff
>
> On Dec 7, 5:12 pm, Berco Beute <[EMAIL PROTECTED]> wrote:
>
> > Is there a template tag to turn an int into a sequence (like 'range')?
> > What I want to do is populate a select widget with the numbers up to
> > the int, like:
>
> > ==
> > 
> >     {% for i in someInt.range %}
> >         {{i}}
> >     {% endfor %}
> > 
> > ==
>
> > Passing the sequence through the context is not an option in my
> > particular case.
>
> > 2B
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



selected ModelMultipleChoiceField

2008-12-08 Thread Abdel Bolanos Martinez

Hi,
i'm new in django and i'm using ModelMultipleChoiceField and all works
fine but i need to 'mark' o 'selected' some model objects from the
queryset

have ever someone did something like that???


Abdel Bolaños Martínez
Ing. Infórmatico
Telf. 266-8562
5to piso, oficina 526, Edificio Beijing, Miramar Trade Center. ETECSA

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django Training

2008-12-08 Thread Steve Holden

I am looking at expanding our training offerings for the coming year,
and a short course in Django looks like it might be popular. There
don't seem to be many Django classes at the moment, and several of the
students from our introductory Python classes expressed interest in
Django.

Without wanting anyone on the list to do my work for me, it would be
useful to see some opinions about what to include. The tutorial gives
people a good start: should we assume that anyone who wants to take
the class has already run through that, or would it be better to start
from scratch?

Django is such a rich platform it would be possible to write several
classes: what material do readers regard as the "essentials of
Django", and what should be relegated to more advanced classes? What
can I do to put a compelling introductory class together?

regards
 Steve
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: reverse problem

2008-12-08 Thread Grigory Fateyev

Hello Dmitry Dzhus!
On Mon, 08 Dec 2008 18:25:47 +0300 you wrote:

> 
> Grigory Fateyev wrote:
> > In all my local projects when I want to use comments contrib, got
> > the error [1]. Django is from last trunk, all *.pyc files from
> > contrib/comments were removed. What it can be?
> 
> Have you wiped out `urls/` subdirectory (left there from previous
> Django version) from `contrib/comments/`?

Thanks a lot! It was correct suggestion.

-- 
Всего наилучшего! Григорий
greg [at] anastasia [dot] ru
Письмо отправлено: 2008/12/08 18:46

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Reducing the number of my view's database queries

2008-12-08 Thread DavidA

If I undestand the problem correctly, in MySQL you could do this in
one query as:

select
m.*,
(select min(created) from model2 where id = m.model2_id) as
first_created,
(select max(created) from model2 where id = m.model2_id) as
last_created
from model1 m
;

I don't know how that translates to the Django ORM (or even if it
does), though.

-Dave

On Dec 8, 12:27 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Sat, 2008-12-06 at 20:56 -0800, erikcw wrote:
> > Hi all,
>
> > I'm trying to write a model query that will return a queryset along
> > with the latest (and earliest) data from 2 related models.
>
> > Right now I'm doing something like this:
>
> > objects = Model1.objects.filter(user=3).select_related() #about 6,000
> > objects
>
> > data = {}
> > for o in objects:
> >     data[o.name] = [o.field1, o.field2]
> >     data[o.name].append(o.field3.model2_set.all().latest('created'))
> > #get latest row from related model2
> >     data[o.name].append(o.model3_set.all().order_by('created')[0])
> > #get earliest row from related model3
>
> > The problem is that this results in a TON of database queries.  This
> > view is taking over a minute to process.  The select_related on the
> > first line doesn't seem to be helping since I'm using latest()/
> > order_by which generates a new query.
>
> > How can I make this more efficient?  Denormalizing the isn't an option
> > since model2 and model 3 are many-to-one.
>
> By the way (since I still haven't worked out the complex SQL to make it
> three queries yet), this last statement isn't correct. Denormalising
> doesn't just mean flattening. You can store a computed dependent field
> in model1 for the related information. So you could, for example, store
> the relevant date and pk value of the related model2 row and update that
> whenever a new model2 is inserted.
>
> Malcolm
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: reverse problem

2008-12-08 Thread Dmitry Dzhus

Grigory Fateyev wrote:
> In all my local projects when I want to use comments contrib, got the
> error [1]. Django is from last trunk, all *.pyc files from
> contrib/comments were removed. What it can be?

Have you wiped out `urls/` subdirectory (left there from previous Django
version) from `contrib/comments/`?
-- 
Happy Hacking.

http://sphinx.net.ru
む


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



i18n and l10n of templates for emails

2008-12-08 Thread Kresimir Tonkovic

Hi!

I'm using templetes to generate the HTML body for some reports I send
daily by email. I do it like this:

context = Context()
context["some_var"] = some_value


resp = render_to_string("daily_report.html", context)

msg = EmailMultiAlternatives(
_(u'Daily report'), _('Please use a html-emabled mail
reader'),
_('[EMAIL PROTECTED]'), ['[EMAIL PROTECTED]'])
msg.attach_alternative(resp, "text/html")
msg.send()

The template is i18n-ized and is actually created from a page template
that works correctly. But these reports are never translated to the
langauge set in settings.py LANGUAGE_CODE, nor have I found any other
way to control i18n of this template's rendering. I guess this has to
do with me using Context instead of RequestContext. Obviously there is
no request here and thus no RequestContext.

Any ideas how I could control 18n in this scenario?

Regards,
Krešimir Tonković

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



User in form wizard

2008-12-08 Thread chewynougat

Could anyone tell me if I can pass the current user to a form wizard
step so I can prepopulate their object details in the form? If so,
how?

Thanks in advance
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Non-displayed fields on admin form get overwritten

2008-12-08 Thread Rajesh Dhawan

>
> The code I pasted (poorly) *is* the model code that causes the
> problem, minus the last couple of field entries.

The code you pasted earlier uses the attribute name 'fields' where it
should use the name 'fieldsets'. The former is used when you are
providing a simple list of field names while the latter is used in
your case (where you are providing groups of field name lists.)



>
> Thanks again for your help. Also, if it would help for me to repaste
> the code using dpaste, let me know.

Yes, I think that will help.

-Rajesh 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Cookie muncher

2008-12-08 Thread globophobe

I am still having trouble with Safari and cookies. I can login only
sometimes with Safari. About half the time I receive an error page.

There is a login box on all the pages of my site. Since I need to set
a test cookie before users login, I have the following code in a class
that is in the base class that is instantiated each request.

# AnonymousUser tracking placeholder.
if not self.request.session.get('online') and not
self.request.session.test_cookie_worked():
self.request.session.set_test_cookie()
else:
if self.request.session.test_cookie_worked():
self.request.session.delete_test_cookie()
self.request.session['online'] = True
# request.user.is_authenticated()
if self.request.user.is_authenticated():
if not DEBUG:
self.request.session.set_expiry(7200)

The following is my login view.

class LoginView(Base):
def __init__(self, *args, **kwargs):
if hasattr(Base, '__init__'):
Base.__init__(self, *args, **kwargs)

def POST(self):
if self.request.session.get('online'):
user = authenticate(username=self.request.POST.get
('username'),
password=self.request.POST.get
('password')
)
if user is not None:
if user.is_active:
login(self.request, user)
self.set_status_code_302('/community/%s/' %
user.username)
else:
if hasattr(self.resource.site, 'private'):
if self.resource.site.private:
self.status_code = 403
else:
self.set_status_code_302('/community/
register/')
else:
self.set_status_code_302('/community/register/')
else:
self.status_code = 500
self.status[500]['error'] = u"You must enable cookies in
your web browser."

The error I receive about 50% of the time with Safari is set during
the last line of the LoginView class.

What might be the problem? Suggestions are appreciated.

Luis.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Help needed debugging a weird MySQL error!

2008-12-08 Thread bruno desthuilliers



On 8 déc, 14:28, taleinat <[EMAIL PROTECTED]> wrote:
> I have a Django application, and I wrote an external script which
> reads and writes to the Django database. I've started getting the
> following exception consistently:
>
> Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of
> sync; you can't run this command now") in  of > ignored

Most probably something to do with transaction handling, I'd say.

> Has anyone had similar problems?
>
> Otherwise, I need some help debugging this. Where do I start?

As usual : extract the minimum code required to reproduce the error,
and run it with pdb.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Help needed debugging a weird MySQL error!

2008-12-08 Thread taleinat

I have a Django application, and I wrote an external script which
reads and writes to the Django database. I've started getting the
following exception consistently:

Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of
sync; you can't run this command now") in > ignored


Has anyone had similar problems?

Otherwise, I need some help debugging this. Where do I start? What
could be the cause of this?


Some technical details: mysql5 5.0.67, mysql-python 1.2.2, Python
2.5.2, Django 1.0, OSX 10.5.5

Thanks,
- Tal
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Strage utils problem

2008-12-08 Thread madhav

Just so that everybody knows how I am running the fcgi daemon:
PYTHONPATH=/repo/django_src /usr/bin/python2.4 manage.py --
settings=PRODUCTION_settings runfcgi method=prefork host=127.0.0.1
port=8080


On Dec 8, 6:00 pm, madhav <[EMAIL PROTECTED]> wrote:
> I have a very strange problem. My project directory has got a
> directory named "utils" and all the modules related to the utils
> folder are not getting imported. All the rest are getting imported.
> That too this problem is only when I run the fcgi daemon(app server).
> When I try to import the same module(which is in utils folder) from
> DJANGO SHELL, its gettings imported properly. I dont know why? And
> that too this problem only resulted AFTER I restarted my production
> server(which means I have restarted my app and web servers). I am of
> the opinion like this is a pythonpath issue and not a thing related to
> the codebase(which remains untouched). Please help me out. What is
> with this utils thing anyway?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Strage utils problem

2008-12-08 Thread madhav

I have a very strange problem. My project directory has got a
directory named "utils" and all the modules related to the utils
folder are not getting imported. All the rest are getting imported.
That too this problem is only when I run the fcgi daemon(app server).
When I try to import the same module(which is in utils folder) from
DJANGO SHELL, its gettings imported properly. I dont know why? And
that too this problem only resulted AFTER I restarted my production
server(which means I have restarted my app and web servers). I am of
the opinion like this is a pythonpath issue and not a thing related to
the codebase(which remains untouched). Please help me out. What is
with this utils thing anyway?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Displaying image stored in models.ImageField

2008-12-08 Thread Craig Spry

Hello All,

Just to add to what I've said below, when I point the browser at the
image url like this:
http://localhost:8000/uploads/comics/john7_web.png

I get a 404.

Craig

On Mon, Dec 8, 2008 at 10:34 PM, Craig Spry <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> I have an image stored in a models.ImageField that looks like this:
> comic = models.ImageField(upload_to='comics')
>
> and I have this in the settings.py
> MEDIA_URL = 'http://localhost:8000/uploads/'
>
> and in the template I have this:
> 
>
> And all I see in the rendered page is the comic.name.  Is there
> anything else I need to setup for this to work?
>
> Thanks,
> Craig Spry
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



reverse problem

2008-12-08 Thread Grigory Fateyev

Hello!

In all my local projects when I want to use comments contrib, got the
error [1]. Django is from last trunk, all *.pyc files from
contrib/comments were removed. What it can be?

Thanks!

[1] Exception Value:Caught an exception while rendering: Reverse
for '' with arguments '()' and
keyword arguments '{}' not found.

Original Traceback (most recent call last):
  File
"/usr/local/lib/python2.5/site-packages/django/template/debug.py", line
71, in render_node result = node.render(context) File
"/usr/local/lib/python2.5/site-packages/django/template/__init__.py",
line 888, in render return func(*resolved_vars) File
"/usr/local/lib/python2.5/site-packages/django/contrib/comments/templatetags/comments.py",
line 246, in comment_form_target return comments.get_form_target() File
"/usr/local/lib/python2.5/site-packages/django/contrib/comments/__init__.py",
line 50, in get_form_target return
urlresolvers.reverse("django.contrib.comments.views.comments.post_comment")
File
"/usr/local/lib/python2.5/site-packages/django/core/urlresolvers.py",
line 254, in reverse *args, **kwargs))) File
"/usr/local/lib/python2.5/site-packages/django/core/urlresolvers.py",
line 243, in reverse "arguments '%s' not found." % (lookup_view, args,
kwargs)) NoReverseMatch: Reverse for '' with arguments '()' and keyword arguments '{}' not found.

-- 
Всего наилучшего! Григорий
greg [at] anastasia [dot] ru
Письмо отправлено: 2008/12/08 13:57

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Displaying image stored in models.ImageField

2008-12-08 Thread Craig Spry

Hello All,

I have an image stored in a models.ImageField that looks like this:
comic = models.ImageField(upload_to='comics')

and I have this in the settings.py
MEDIA_URL = 'http://localhost:8000/uploads/'

and in the template I have this:


And all I see in the rendered page is the comic.name.  Is there
anything else I need to setup for this to work?

Thanks,
Craig Spry

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: fields in object.values()

2008-12-08 Thread bruno desthuilliers



On 8 déc, 08:53, Sotiris Kazakis <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Thank you for your answer.
>
> I try : tbData = tableName.objects.values(*strFld.split(","))
>
> but that error appears :
>
>   File "/var/lib/python-support/python2.4/django/db/models/sql/query.py", 
> line 1503, in add_fields
> field, target, u2, joins, u3, u4 = self.setup_joins(
> AttributeError: 'list' object has no attribute 'split'
> because strFld.split(",") --> produce a list

>>> fnames=['target_user', 'source_user']
>>> Friendship.objects.values(*fnames)
[{'source_user': 1L, 'target_user': 2L}]
>>> fields = "target_user,source_user"
>>> Friendship.objects.values(*fields.split(','))
[{'source_user': 1L, 'target_user': 2L}]
>>>

str.split() indeed returns a list, but that's obviously not the cause
of your problem here.



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: fields in object.values()

2008-12-08 Thread bruno desthuilliers

On 7 déc, 21:48, "sotiris.kazakis" <[EMAIL PROTECTED]> wrote:
> hello,
>
> I search a lot about the use of object.values() but don't get what I
> want.
>
> I want to put dynamically (with a string ?)

Better to use a sequence of strings IMHO.

> the fields that I want to
> get from a model. i.e.:
>
> #model
> Class Test(model.Model)
>Id = models.AutoField(primary_key=True, verbose_name="a/a")
>Name = models.CharField(max_length=90, unique=True,
> verbose_name="Name")
>Description = models.CharField(max_length=24,
> verbose_name="Description")
>
> #function to view the data of my table with strFld
> def tbView(tbName,strFld=None):
>  tableName=eval(tbName)   # class instance

eval() is the wrong solution for 99.9% use cases. If you want a
generic solution, better to use "app_label" "model_name" as argument
and db.models.loading.get_model (cf below).

>  tbFields=tableName._meta.fields# load table fields

you actually don't use this in the rest of the code...

> tbData=tableName.objects.values(strFld)  #load only field in
> strFld
>
> return render_to_response('myView.html',
> {'tbData':tbData,'name':tbName})
>
> I would like to get the data from selected fields with this :
>
> strFld="Name,Description"
> tbView('Test',strFld)
>
> When I use that get this error :
>
> raise FieldError("Cannot resolve keyword %r into field. "
> FieldError: Cannot resolve keyword 'Name,Description' into field.
> Choices are: Id, Name, Description.
>
> What is wrong ?

You need to pass a sequence of field names. Which you can build from
strFld:

# assuming ',' is the delimiter:
  fieldnames = filter(None, [n.strip() for n in strFld.split(',')])


Now note that the HTTP protocol allow multiple values for a same key
in a GET or POST request, which is of course supported by Django's
request.GET, request.POST and request.REQUEST QueryDict objects.

here's a possible fix (untested, and without error handling).

I allowed myself to use a more pythonic naming scheme (cf Python's
naming conventions: http://www.python.org/dev/peps/pep-0008/)



from django.db.models.loading import get_model

def table_view(request, app_label, model_name):
# example url with querystring:
# /myproject/table_view/app_label/model_name/?field=foo=bar

model = get_model(app_label, model_name)
fields = request.REQUEST.getlist('field')
data = model.objects.all().values(*fields)
context = dict(data=data, app_label=app_label,
model_name=model_name)
return render_to_response('my_view.html', context)

HTH
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Combine model form with a formset

2008-12-08 Thread Alistair Marshall

I have been hunting around but can't find a solution to this problem:

It is probably best described with an example

Example:

class Author(models.Model):
name= models.CharField()
location = models.CharField()

class Book(models.Model):
name= models.CharField()
author   = models.ForeignKey(Author)

I want to be able to enter/edit details about both the author AND the
books the author has written in the same form/view - I have tried
using a form wizard though I have just gotten lost and am not sure if
this is the best method of solving this or if it is even possible to
include a formset within a form wizard.

Has anyone else had this user case and is there a best method?

Thanks
Alistair
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Two different django version on the same server?

2008-12-08 Thread Pablo Ruiz Múzquiz

Got it!

I've been actively using GNU/Linux since mid-90's and it's always the
same issue... permissions...

I got the OTHER_DJANGO_PATH pointing to a root-only directory, so
apache (or mod_python), wisely, ignored it and, so, went on until site-
packages gloriously appeared.

I just can't believe I keep falling into these every now and then.

Thanks! you made feel confident about the pythonpath so I started
looking elsewhere (though I though I had that permission error already
nailed down...) :-)

Pablo


On Dec 8, 12:27 pm, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> On Dec 8, 10:15 pm, Pablo Ruiz Múzquiz <[EMAIL PROTECTED]> wrote:
>
> > Hmm. That is exactly what I meant with "No matter what I do with
> > Apache's PythonPath".
> > I have that same configuration you posted and /admin (and other stuff)
> > won't work (most certainly because of the django version mismatch)
>
> > The two errrors are "no module named urls" and "Viewdoesnotexist ..
> > could not impot login. cannot import name validators"
>
> > Thanks anyway, I'll keep trying!
>
> Post your actual configuration then.
>
> There are various subtleties in using mod_python and since you haven't
> posted your actual configuration, you could be doing something obvious
> wrong, but we cannot tell. Saying you have the same as other poster is
> not enough as what they posted doesn't explain everything.
>
> > Pablo
>
> > On Dec 7, 8:08 pm, Adi Sieker <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
>
> > > On 07.12.2008, at 16:56, Pablo Ruiz Múzquiz wrote:
>
> > > > Hi all,
>
> > > > I'm afraid I googled and googled with no success. Django official docs
> > > > or my django book weren't of any help either.
>
> > > > I've got a "legacy" django project which was developed using 0.97svn a
> > > > year ago and a brand new SVN one, sharing the same server.
>
> > > > Django 097 lives at /srv/whatever/django097/django while Django SVN at
> > > > the usual site-packages location.
>
> > > > No matter what I do with Apache's PythonPath, the virtualhost  
> > > > referring
> > > > to the old project will load  the SVN version and, thus, /admin and  
> > > > some
> > > > template handling will fail to load.
>
> > > > Any clues? Thanks in advance,
>
> > > I'm doing that on one of my domains with mod_python and it's working  
> > > just fine.
> > > Here is my relevant apache config.
>
> > > 
> > >          ServerName vhost1
> > >      
> > >          SetHandler python-program
> > >          PythonHandler django.core.handlers.modpython
> > >          SetEnv DJANGO_SETTINGS_MODULE project.settings
> > >          PythonPath "['', \
> > >                       '', \
> > >                       ''] + sys.path"
> > >      
> > > 
>
> > > in this VirtualHost  points to a pre newforms admin  
> > > version of django and then a duplicate of this VirtualHost where the  
> > >  points to a trunk version of django.
> > > The _really_ important part is that sys.path comes after the version  
> > > you want to use for this host.
> > > Since sys.path will include your site.packages it'll find the trunk  
> > > version first.
>
> > > adi
>
> > > --
> > > Adi J. Sieker         mobile: +49 - 178 - 88 5 88 13
> > > Freelance developer   skype:  adijsieker
> > > SAP-Consultant        web:    http://www.sieker.info/profile
> > >                        openbc:https://www.openbc.com/hp/
> > > AdiJoerg_Sieker/
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Two different django version on the same server?

2008-12-08 Thread Graham Dumpleton



On Dec 8, 10:15 pm, Pablo Ruiz Múzquiz <[EMAIL PROTECTED]> wrote:
> Hmm. That is exactly what I meant with "No matter what I do with
> Apache's PythonPath".
> I have that same configuration you posted and /admin (and other stuff)
> won't work (most certainly because of the django version mismatch)
>
> The two errrors are "no module named urls" and "Viewdoesnotexist ..
> could not impot login. cannot import name validators"
>
> Thanks anyway, I'll keep trying!

Post your actual configuration then.

There are various subtleties in using mod_python and since you haven't
posted your actual configuration, you could be doing something obvious
wrong, but we cannot tell. Saying you have the same as other poster is
not enough as what they posted doesn't explain everything.

> Pablo
>
> On Dec 7, 8:08 pm, Adi Sieker <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > On 07.12.2008, at 16:56, Pablo Ruiz Múzquiz wrote:
>
> > > Hi all,
>
> > > I'm afraid I googled and googled with no success. Django official docs
> > > or my django book weren't of any help either.
>
> > > I've got a "legacy" django project which was developed using 0.97svn a
> > > year ago and a brand new SVN one, sharing the same server.
>
> > > Django 097 lives at /srv/whatever/django097/django while Django SVN at
> > > the usual site-packages location.
>
> > > No matter what I do with Apache's PythonPath, the virtualhost  
> > > referring
> > > to the old project will load  the SVN version and, thus, /admin and  
> > > some
> > > template handling will fail to load.
>
> > > Any clues? Thanks in advance,
>
> > I'm doing that on one of my domains with mod_python and it's working  
> > just fine.
> > Here is my relevant apache config.
>
> > 
> >          ServerName vhost1
> >      
> >          SetHandler python-program
> >          PythonHandler django.core.handlers.modpython
> >          SetEnv DJANGO_SETTINGS_MODULE project.settings
> >          PythonPath "['', \
> >                       '', \
> >                       ''] + sys.path"
> >      
> > 
>
> > in this VirtualHost  points to a pre newforms admin  
> > version of django and then a duplicate of this VirtualHost where the  
> >  points to a trunk version of django.
> > The _really_ important part is that sys.path comes after the version  
> > you want to use for this host.
> > Since sys.path will include your site.packages it'll find the trunk  
> > version first.
>
> > adi
>
> > --
> > Adi J. Sieker         mobile: +49 - 178 - 88 5 88 13
> > Freelance developer   skype:  adijsieker
> > SAP-Consultant        web:    http://www.sieker.info/profile
> >                        openbc:https://www.openbc.com/hp/
> > AdiJoerg_Sieker/
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Two different django version on the same server?

2008-12-08 Thread Pablo Ruiz Múzquiz

Hmm. That is exactly what I meant with "No matter what I do with
Apache's PythonPath".
I have that same configuration you posted and /admin (and other stuff)
won't work (most certainly because of the django version mismatch)

The two errrors are "no module named urls" and "Viewdoesnotexist ..
could not impot login. cannot import name validators"

Thanks anyway, I'll keep trying!

Pablo

On Dec 7, 8:08 pm, Adi Sieker <[EMAIL PROTECTED]> wrote:
> Hi,
>
> On 07.12.2008, at 16:56, Pablo Ruiz Múzquiz wrote:
>
>
>
> > Hi all,
>
> > I'm afraid I googled and googled with no success. Django official docs
> > or my django book weren't of any help either.
>
> > I've got a "legacy" django project which was developed using 0.97svn a
> > year ago and a brand new SVN one, sharing the same server.
>
> > Django 097 lives at /srv/whatever/django097/django while Django SVN at
> > the usual site-packages location.
>
> > No matter what I do with Apache's PythonPath, the virtualhost  
> > referring
> > to the old project will load  the SVN version and, thus, /admin and  
> > some
> > template handling will fail to load.
>
> > Any clues? Thanks in advance,
>
> I'm doing that on one of my domains with mod_python and it's working  
> just fine.
> Here is my relevant apache config.
>
> 
>          ServerName vhost1
>      
>          SetHandler python-program
>          PythonHandler django.core.handlers.modpython
>          SetEnv DJANGO_SETTINGS_MODULE project.settings
>          PythonPath "['', \
>                       '', \
>                       ''] + sys.path"
>      
> 
>
> in this VirtualHost  points to a pre newforms admin  
> version of django and then a duplicate of this VirtualHost where the  
>  points to a trunk version of django.
> The _really_ important part is that sys.path comes after the version  
> you want to use for this host.
> Since sys.path will include your site.packages it'll find the trunk  
> version first.
>
> adi
>
> --
> Adi J. Sieker         mobile: +49 - 178 - 88 5 88 13
> Freelance developer   skype:  adijsieker
> SAP-Consultant        web:    http://www.sieker.info/profile
>                        openbc:https://www.openbc.com/hp/
> AdiJoerg_Sieker/
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Writing SOAP Server in Django

2008-12-08 Thread 董诣

danlester 写道:
> There are some posts on this list from a year or two ago suggesting
> that there is a contrib module allowing a SOAP server to be built in
> Django easily. It certainly isn't part of Django 1.0.2...
>
> Has anyone built a SOAP server using Django recently?
>
> I've been able to get something going using soaplib (http://
> trac.optio.webfactional.com/) and a corresponding Django 'adapter'
> found on djangosnippets.org.
>
> soaplib is a great library, but just doesn't quite seem complete
> enough or supported anymore... But it even generates WSDL!
>
> I think I've outgrown it, though, and would like to generate my WSDL
> by hand anyway, using a SOAP library that might be more flexible and
> up-to-date (maybe ZSI...?)
>
> Any thoughts about sticking this into Django? Or if anyone wants to
> hear more about my adventures so far, please get in touch.
>
> Dan
>   

I am trying to use django to build a soap interface for my probject too
I found an article about it :

http://code.djangoproject.com/ticket/552



it seems to be written some years before, I modify some place to run
but I still can't figure out how to use it


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: help with file uploads

2008-12-08 Thread Alan
Hi There,
So, I am trying "
http://docs.djangoproject.com/en/dev/topics/http/file-uploads/;, but can't
see the results.

I mean, I am confused because I don't know where to place the template
(which I believe has to be "contact.html"). I have a folder
"/mysite/templates/" and the tutorial "mysite/polls" works fine. Thus I have
"/mysite/templates/polls" and "/mysite/templates/admin".

So I am trying to place "/mysite/templates/contact.html" and when trying "
http://localhost:8000/contact/; I got:

Exception Type: TypeError at /contact/ Exception Value: 'str' object is not
callable

I still have no idea about how to follow this debugging message.

Should I have to have "/mysite/templates/contact/contact.html"?

Besides, what to put in urls.py ("/mysite/urls.py")?

I am trying:

from django.conf.urls.defaults import patterns, include


# Uncomment the next two lines to enable the admin:

from django.contrib import admin

admin.autodiscover()


urlpatterns = patterns('',

(r'^admin/(.*)', admin.site.root),

(r'^contact/', 'contact'),

(r'^jobs/', include('mysite.jobs.urls')),

)

"http://localhost:8000/jobs/; and "http://localhost:8000/admin/; work fines.

Needless to say I am a naive novice to Django.

If someone can point out what I am missing in "
http://docs.djangoproject.com/en/dev/topics/http/file-uploads/; I would
deeply grateful.

Many thanks in advance.

Alan

On Mon, Dec 8, 2008 at 09:37, Alan <[EMAIL PROTECTED]> wrote:

> Thank you very much Karen.
> Indeed, reading Django docs I was getting something very close to what you
> sent to me, but I am still failing to render (still have difficult to debug,
> but getting there). With your example I believe can solve the issues I have.
>
> I will describe what I want to do.
>
> We have a python application that does heavy calculation (NMR structure
> determination related). So, our (draft) portal should be a page where one
> can upload a file (zip, containing the project to be calculated). Once
> uploaded, I would like to keep in a DB (at first), project name, date &
> time, path location. Once uploaded, the file should be unzipped in a
> specific folder (path location, so I don't want to keep the zip file neither
> in filesystem nor in DB) and call our python application to run it. I hope I
> can enable this draft portal to send an e-mail when job is done with status
> (failed or done, for example).
>
> Eventually, I intend to put a log in (user has to be identified) and a
> parsed page (where user can tweak some parameters before clicking "Run"
> bottom).
>
> Once again, thanks for your help.
>
> Alan
>
> On Fri, Dec 5, 2008 at 16:32, Karen Tracey <[EMAIL PROTECTED]> wrote:
>
>> On Thu, Dec 4, 2008 at 6:12 PM, Alan <[EMAIL PROTECTED]> wrote:
>>
>>> Hi there!
>>> Although I have some experience in Python and Plone and have done Django
>>> tutorial, I am still not getting how to do a simple task I proposed myself:
>>> build a submitting page for a zip file.
>>>
>>> So I am looking at
>>> http://docs.djangoproject.com/en/dev/topics/http/file-uploads/
>>>
>>> It seems to have all I need, but I still don't know well how to connect
>>> the dots. So, it would be really great if I could put my hands in a example
>>> or, better, tutorial, of how to build such a page for submitting a file.
>>>
>>> The difficult I find is that when I was building webpages I used to think
>>> first the html code and then the rest, but with Django, I feel I have to
>>> think first models, but then I still lack how to link with view.
>>>
>>
>> I think it makes sense to think first in terms of what you want to present
>> to the user for your task, which in Django would be a combination of a form
>> and template.  From there start thinking about what your view code needs to
>> do to manipulate the submitted form data to be saved in one or more model
>> instances.  What models you want to create rather depends on more than the
>> one simple task of submitting a zip file -- what sorts of things do you want
>> to do with the submitted zip files after they've been been submitted?
>>
>> If the form for your task maps nicely to a single model then perhaps it
>> makes sense to use a ModelForm, but maybe not.  In some cases what should
>> logically be presented to the user doesn't map so nicely to what it makes
>> logical sense to keep in your database, and then it's best to give up on the
>> very easy ModelForm approach and write some custom forms and code that deals
>> with mapping from what is best for the user to deal with to what is best to
>> store in the DB.
>>
>> To give a concrete example, I have a crossword puzzle database to which I
>> upload new published puzzles daily.  Models in the DB include Publishers,
>> Authors, Puzzles, Entries, and Clues.  There is no PuzzleFile model --
>> uploading a new puzzle file will involve creating a new Puzzle instance, may
>> involve creating a new Author instance, many new Entries instances, many new
>> Clues, etc.  Uploading and 

Re: templates database access

2008-12-08 Thread Daniel Roseman

On Dec 8, 10:25 am, Vicky <[EMAIL PROTECTED]> wrote:
> Is there any way to insert, retrieve, delete and update tables in a
> database from templates itself?

Well, retrieving is what you do when you display data, but for the
rest the answer is *definitely not omg why would you want to do such a
horrible thing*.

--
DR.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



templates database access

2008-12-08 Thread Vicky

Is there any way to insert, retrieve, delete and update tables in a
database from templates itself?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ifequals in templates

2008-12-08 Thread Vicky
Yea that was the mistake :) it wrks fine nw

On Dec 8, 3:16 pm, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Dec 8, 9:31 am, Vicky <[EMAIL PROTECTED]> wrote:
>
>
>
> > I tried to use the code
> > below:
> >                                                {% ifequal oftype
> > 'first_name' %}
> >                                                         {% for item in 
> > datas.first_name %}
> >                                                                  {{ 
> > item }} 
> >                                                         {% endfor %}
> >                                                 {% endifequal %}
>
> >                                                 {% ifequal oftype 
> > 'last_name' %}
> >                                                         {% for item in 
> > datas.last_name %}
> >                                                                  {{ 
> > item }} 
> >                                                         {% endfor %}
> >                                                 {% endifequal %}
>
> > But it didnt even execute either of the blocks. can anyone help me
> > with this?
>
> Are you sure oftype is equal to either of these values? Try putting
> {{ oftype }} before the loop to see what it actually contains.
> --
> DR.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ifequals in templates

2008-12-08 Thread Daniel Roseman
On Dec 8, 9:31 am, Vicky <[EMAIL PROTECTED]> wrote:
> I tried to use the code
> below:
>                                                {% ifequal oftype
> 'first_name' %}
>                                                         {% for item in 
> datas.first_name %}
>                                                                  {{ 
> item }} 
>                                                         {% endfor %}
>                                                 {% endifequal %}
>
>                                                 {% ifequal oftype 'last_name' 
> %}
>                                                         {% for item in 
> datas.last_name %}
>                                                                  {{ 
> item }} 
>                                                         {% endfor %}
>                                                 {% endifequal %}
>
> But it didnt even execute either of the blocks. can anyone help me
> with this?

Are you sure oftype is equal to either of these values? Try putting
{{ oftype }} before the loop to see what it actually contains.
--
DR.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: help with file uploads

2008-12-08 Thread Alan
Thank you very much Karen.
Indeed, reading Django docs I was getting something very close to what you
sent to me, but I am still failing to render (still have difficult to debug,
but getting there). With your example I believe can solve the issues I have.

I will describe what I want to do.

We have a python application that does heavy calculation (NMR structure
determination related). So, our (draft) portal should be a page where one
can upload a file (zip, containing the project to be calculated). Once
uploaded, I would like to keep in a DB (at first), project name, date &
time, path location. Once uploaded, the file should be unzipped in a
specific folder (path location, so I don't want to keep the zip file neither
in filesystem nor in DB) and call our python application to run it. I hope I
can enable this draft portal to send an e-mail when job is done with status
(failed or done, for example).

Eventually, I intend to put a log in (user has to be identified) and a
parsed page (where user can tweak some parameters before clicking "Run"
bottom).

Once again, thanks for your help.

Alan

On Fri, Dec 5, 2008 at 16:32, Karen Tracey <[EMAIL PROTECTED]> wrote:

> On Thu, Dec 4, 2008 at 6:12 PM, Alan <[EMAIL PROTECTED]> wrote:
>
>> Hi there!
>> Although I have some experience in Python and Plone and have done Django
>> tutorial, I am still not getting how to do a simple task I proposed myself:
>> build a submitting page for a zip file.
>>
>> So I am looking at
>> http://docs.djangoproject.com/en/dev/topics/http/file-uploads/
>>
>> It seems to have all I need, but I still don't know well how to connect
>> the dots. So, it would be really great if I could put my hands in a example
>> or, better, tutorial, of how to build such a page for submitting a file.
>>
>> The difficult I find is that when I was building webpages I used to think
>> first the html code and then the rest, but with Django, I feel I have to
>> think first models, but then I still lack how to link with view.
>>
>
> I think it makes sense to think first in terms of what you want to present
> to the user for your task, which in Django would be a combination of a form
> and template.  From there start thinking about what your view code needs to
> do to manipulate the submitted form data to be saved in one or more model
> instances.  What models you want to create rather depends on more than the
> one simple task of submitting a zip file -- what sorts of things do you want
> to do with the submitted zip files after they've been been submitted?
>
> If the form for your task maps nicely to a single model then perhaps it
> makes sense to use a ModelForm, but maybe not.  In some cases what should
> logically be presented to the user doesn't map so nicely to what it makes
> logical sense to keep in your database, and then it's best to give up on the
> very easy ModelForm approach and write some custom forms and code that deals
> with mapping from what is best for the user to deal with to what is best to
> store in the DB.
>
> To give a concrete example, I have a crossword puzzle database to which I
> upload new published puzzles daily.  Models in the DB include Publishers,
> Authors, Puzzles, Entries, and Clues.  There is no PuzzleFile model --
> uploading a new puzzle file will involve creating a new Puzzle instance, may
> involve creating a new Author instance, many new Entries instances, many new
> Clues, etc.  Uploading and adding a puzzle is a two step process, the basic
> upload form is very simple and doesn't involve any models. The file is
> stashed in a staging area where it can be found and processed during the add
> step, which is where actual DB models are created/updated.  In case it's of
> any illustrative use, here's the basics of the upload code:
> http://dpaste.com/96432/ -- form, view, and template.
>
> Karen
>
> >
>


-- 
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.
>>http://www.bio.cam.ac.uk/~awd28<<

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ifequals in templates

2008-12-08 Thread Vicky

I tried to use the code
below:
   {% ifequal oftype
'first_name' %}
{% for item in 
datas.first_name %}
 {{ item 
}} 
{% endfor %}
{% endifequal %}

{% ifequal oftype 'last_name' %}
{% for item in 
datas.last_name %}
 {{ item 
}} 
{% endfor %}
{% endifequal %}

But it didnt even execute either of the blocks. can anyone help me
with this?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---