Re: Saving a ModelForm for the current user?

2010-04-18 Thread David Lindquist
I got it working, thanks to your suggestion. Here is what I did:

# in forms.py

class SiteForm(forms.ModelForm):
class Meta:
model = Site
exclude = ('user',)

def __init__(self, user, *args, **kwargs):
self.user = user
super(SiteForm, self).__init__(*args, **kwargs)

def clean_url(self):
url = self.cleaned_data['url']
try:
Site.objects.get(user=self.user, url=url)
except Site.DoesNotExist:
pass
else:
raise forms.ValidationError(_('Site with this URL already
exists.'))
return url

# in views.py

@login_required
def site_add(request):
form = SiteForm(request.user, request.POST or None)

if form.is_valid():
site = form.save(commit=False)
site.user = request.user
site.save()
return redirect(...)

return render_to_response(...)


On Apr 18, 7:52 am, David Lindquist  wrote:
> Thanks Georg. I will give that a try.
>
> On Apr 18, 7:45 am, "ge...@aquarianhouse.com"
>
>
>
>
>
>  wrote:
> > ok now i got it :)
>
> > i would do this:
>
> > class SiteForm(forms.ModelForm):
>
> >     def __init__(user, *args, **kwargs):
> >        self.user = user
> >        super(SiteForm, self).__init__(*args, **kwargs)
>
> >     class Meta:
> >         model = Site
> >         exclude = ('user',)
>
> >     def clean_url(self):
> >        #check here and give an error...
>
> > form = SiteForm(request.user, request.POST)
>
> > m = form.save(commit=False)
> > m.user = request.user
> > m.save()
>
> > something like this :)
>
> > On Apr 18, 4:32 pm, David Lindquist  wrote:
>
> > > Thanks for the reply.
>
> > > The problem I have with that solution is that it occurs after form
> > > validation takes place. Notice that in my Site model the url and user
> > > fields are specified as being unique_together. If I set the user as
> > > you suggest, I still run the risk of a database error.
>
> > > Is there another way to accomplish this?
>
> > > On Apr 18, 3:14 am, "ge...@aquarianhouse.com"
>
> > >  wrote:
> > > > use commit=False
>
> > > > m = form.save(commit=False)
> > > > m.user = request.user
> > > > m.save()
>
> > > > On Apr 18, 6:06 am, David Lindquist  wrote:
>
> > > > > Greetings,
>
> > > > > I am trying to solve what seems like an easy problem, but the solution
> > > > > eludes me even after many Google searches.
>
> > > > > I have a simple model:
>
> > > > > class Site(models.Model):
> > > > >     user = models.ForeignKey(User)
> > > > >     url = models.URLField()
>
> > > > >     class Meta:
> > > > >         unique_together = (('user', 'url'),)
>
> > > > > And an equally simple ModelForm:
>
> > > > > class SiteForm(forms.ModelForm):
> > > > >     class Meta:
> > > > >         model = Site
> > > > >         exclude = ('user',)
>
> > > > > I exclude the user field because I want to be able to save a Site
> > > > > object for the currently logged in user. But no matter how I try to
> > > > > set the user in the view, form.save() raises an IntegrityError
> > > > > ("Column 'user_id' cannot be null").
>
> > > > > I know I could include the user field and generate the form with a
> > > > > hidden field using the pk of the current user, but that seems like it
> > > > > could be easily altered.
>
> > > > > What is the best approach for 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-us...@googlegroups.com.
> > > > > To unsubscribe from this group, send email to 
> > > > > django-users+unsubscr...@googlegroups.com.
> > > > > For more options, visit this group 
> > > > > athttp://groups.google.com/group/django-users?hl=en.
>
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups "Django users" group.
> > > > To post to this group, send email to django-us...@googlegroups.com.
> > > > To unsubscribe from this group, send email

Re: Saving a ModelForm for the current user?

2010-04-18 Thread David Lindquist
Thanks Georg. I will give that a try.

On Apr 18, 7:45 am, "ge...@aquarianhouse.com"
 wrote:
> ok now i got it :)
>
> i would do this:
>
> class SiteForm(forms.ModelForm):
>
>     def __init__(user, *args, **kwargs):
>        self.user = user
>        super(SiteForm, self).__init__(*args, **kwargs)
>
>     class Meta:
>         model = Site
>         exclude = ('user',)
>
>     def clean_url(self):
>        #check here and give an error...
>
> form = SiteForm(request.user, request.POST)
>
> m = form.save(commit=False)
> m.user = request.user
> m.save()
>
> something like this :)
>
> On Apr 18, 4:32 pm, David Lindquist  wrote:
>
>
>
>
>
> > Thanks for the reply.
>
> > The problem I have with that solution is that it occurs after form
> > validation takes place. Notice that in my Site model the url and user
> > fields are specified as being unique_together. If I set the user as
> > you suggest, I still run the risk of a database error.
>
> > Is there another way to accomplish this?
>
> > On Apr 18, 3:14 am, "ge...@aquarianhouse.com"
>
> >  wrote:
> > > use commit=False
>
> > > m = form.save(commit=False)
> > > m.user = request.user
> > > m.save()
>
> > > On Apr 18, 6:06 am, David Lindquist  wrote:
>
> > > > Greetings,
>
> > > > I am trying to solve what seems like an easy problem, but the solution
> > > > eludes me even after many Google searches.
>
> > > > I have a simple model:
>
> > > > class Site(models.Model):
> > > >     user = models.ForeignKey(User)
> > > >     url = models.URLField()
>
> > > >     class Meta:
> > > >         unique_together = (('user', 'url'),)
>
> > > > And an equally simple ModelForm:
>
> > > > class SiteForm(forms.ModelForm):
> > > >     class Meta:
> > > >         model = Site
> > > >         exclude = ('user',)
>
> > > > I exclude the user field because I want to be able to save a Site
> > > > object for the currently logged in user. But no matter how I try to
> > > > set the user in the view, form.save() raises an IntegrityError
> > > > ("Column 'user_id' cannot be null").
>
> > > > I know I could include the user field and generate the form with a
> > > > hidden field using the pk of the current user, but that seems like it
> > > > could be easily altered.
>
> > > > What is the best approach for 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-us...@googlegroups.com.
> > > > To unsubscribe from this group, send email to 
> > > > django-users+unsubscr...@googlegroups.com.
> > > > For more options, visit this group 
> > > > athttp://groups.google.com/group/django-users?hl=en.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Saving a ModelForm for the current user?

2010-04-18 Thread David Lindquist
Thanks for the reply.

The problem I have with that solution is that it occurs after form
validation takes place. Notice that in my Site model the url and user
fields are specified as being unique_together. If I set the user as
you suggest, I still run the risk of a database error.

Is there another way to accomplish this?

On Apr 18, 3:14 am, "ge...@aquarianhouse.com"
 wrote:
> use commit=False
>
> m = form.save(commit=False)
> m.user = request.user
> m.save()
>
> On Apr 18, 6:06 am, David Lindquist  wrote:
>
>
>
>
>
> > Greetings,
>
> > I am trying to solve what seems like an easy problem, but the solution
> > eludes me even after many Google searches.
>
> > I have a simple model:
>
> > class Site(models.Model):
> >     user = models.ForeignKey(User)
> >     url = models.URLField()
>
> >     class Meta:
> >         unique_together = (('user', 'url'),)
>
> > And an equally simple ModelForm:
>
> > class SiteForm(forms.ModelForm):
> >     class Meta:
> >         model = Site
> >         exclude = ('user',)
>
> > I exclude the user field because I want to be able to save a Site
> > object for the currently logged in user. But no matter how I try to
> > set the user in the view, form.save() raises an IntegrityError
> > ("Column 'user_id' cannot be null").
>
> > I know I could include the user field and generate the form with a
> > hidden field using the pk of the current user, but that seems like it
> > could be easily altered.
>
> > What is the best approach for 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-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Saving a ModelForm for the current user?

2010-04-17 Thread David Lindquist
Greetings,

I am trying to solve what seems like an easy problem, but the solution
eludes me even after many Google searches.

I have a simple model:

class Site(models.Model):
user = models.ForeignKey(User)
url = models.URLField()

class Meta:
unique_together = (('user', 'url'),)

And an equally simple ModelForm:

class SiteForm(forms.ModelForm):
class Meta:
model = Site
exclude = ('user',)

I exclude the user field because I want to be able to save a Site
object for the currently logged in user. But no matter how I try to
set the user in the view, form.save() raises an IntegrityError
("Column 'user_id' cannot be null").

I know I could include the user field and generate the form with a
hidden field using the pk of the current user, but that seems like it
could be easily altered.

What is the best approach for 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Bug in manage.py?

2009-07-13 Thread David Lindquist

D'oh! OK, I am an idiot. I did not create the app with `manage.py
startapp`. I simply created the directory on the command line. Django
does in fact complain.

Guess I got what I deserved ;)

On Jul 13, 4:01 pm, David Lindquist  wrote:
> Hi Everyone,
>
> I discovered by accident that if you have an app with the same name as
> the project, then `python manage.py shell` (and similar commands)
> cannot import the settings file. I assume this is due to how Django
> updates sys.path.
>
> I would expect Django update sys.path to look in the project directory
> first, or at least complain if it detects an app with the same name as
> the project.
>
> The fix was easy enough; I just changed my app name. But would you
> consider this a bug?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Bug in manage.py?

2009-07-13 Thread David Lindquist

Hi Everyone,

I discovered by accident that if you have an app with the same name as
the project, then `python manage.py shell` (and similar commands)
cannot import the settings file. I assume this is due to how Django
updates sys.path.

I would expect Django update sys.path to look in the project directory
first, or at least complain if it detects an app with the same name as
the project.

The fix was easy enough; I just changed my app name. But would you
consider this a bug?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Odd ORM behavior

2009-03-26 Thread David Lindquist
Thanks Karen! I knew it had to be something newb-ish I was doing. :)

On Mar 26, 2009, at 10:04 AM, Karen Tracey wrote:

> On Thu, Mar 26, 2009 at 12:53 PM, David Lindquist  
>  wrote:
>
> I am noticing some odd SQL being generated for certain queries. For
> example, if I type the following in the shell:
>
>  >>> TroubleCode.objects.all()[:5]
>
> and then I look at the db queries:
>
>  >>> from django.db import connection
>  >>> connection.queries
>
> I get the desired query, plus 5 extra queries corresponding to the
> number in the LIMIT clause:
>
> Your __unicode__ method for TroubleCode:
>
> def __unicode__(self):
> return '%s: %s' % (self.number, self.make)
>
> accesses self.make, which is a ForeignKey.  Its unicode method  
> accesses one of its fields, but since you did not use select_related 
> () in retrieving your TroubleCode queryset the related model's  
> fields were not pre-loaded during the initial query.  So for  
> printing out the repr of the queryset, an individual query must be  
> made for each TroubleCode, to access the related object's 'make'  
> CharField.
>
> Karen
>
>
> http://dpaste.com/19538/
>
> Here are the models I am using:
>
> http://dpaste.com/19541/
>
> Any idea why this is happening? I don't notice this behavior in other
> models.
>
> I am using Django 1.0.2
>
>
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Odd ORM behavior

2009-03-26 Thread David Lindquist

I am noticing some odd SQL being generated for certain queries. For  
example, if I type the following in the shell:

 >>> TroubleCode.objects.all()[:5]

and then I look at the db queries:

 >>> from django.db import connection
 >>> connection.queries

I get the desired query, plus 5 extra queries corresponding to the  
number in the LIMIT clause:

http://dpaste.com/19538/

Here are the models I am using:

http://dpaste.com/19541/

Any idea why this is happening? I don't notice this behavior in other  
models.

I am using Django 1.0.2

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: will dmigrations be merged into django codebase?

2009-03-25 Thread David Lindquist


On Mar 25, 2009, at 4:54 PM, Russell Keith-Magee wrote:

>
> On Thu, Mar 26, 2009 at 8:42 AM, Joshua Partogi  
>  wrote:
>>
>> Is there any chance dmigrations
>> (http://code.google.com/p/dmigrations/) will be merged into django
>> codebase? Because it removes the pain for db migrations :-D
>
> dmigrations is one of several database schema migration projects that
> exists in the community. Given the feature set that is available to
> other migration projects (in particular, Django Evolution and South),
> it is unlikely that dmigrations will be merged into Django as-is.
> However, adding schema migration is on the radar as something that we
> want to add.
>
> For more details, search the Django mailing lists - this comes up
> fairly regularly. Also, look on YouTube for the DjangoCon video where
> the developers of Django Evolution, South and dmigrations discuss
> their projects and the prospects for integrating a migration project
> into trunk.
>
> Yours,
> Russ Magee %-)
>

I have a question about schema migration that is a bit tangential to  
this thread, but it is something I have always wondered about:

Why has it taken so long for Django to acquire this functionality  
when a framework like Ruby on Rails has had it for years? Is there  
something about Django that makes it more difficult to implement? Was  
the Rails implementation hastily added? Is it simply low on the  
priority list?

Just curious.


> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: OT: svn and '$Id$'

2009-03-24 Thread David Lindquist

On Mar 24, 2009, at 10:09 AM, Alan wrote:

> Hi there,
>
> It's a bit off topic but I guess appropriate anyway.
>
> So I want to use '$Id$' in my *.py files where '$Id$' got replaced  
> when I commit my files via svn.
>
> But I googled and I still couldn't make it work. Can somebody tell  
> to make it work? I would like to get at least date and time when  
> the files are committed ( svn on googlecode) in the file itself.
>
> Many thanks in advance.
>
> Alan
>
> -- 
> 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<<
>

Rather, that should be:

find . -name "*.py" -exec svn propset svn:keywords "Id" {} \;


> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: OT: svn and '$Id$'

2009-03-24 Thread David Lindquist

On Mar 24, 2009, at 10:09 AM, Alan wrote:

> Hi there,
>
> It's a bit off topic but I guess appropriate anyway.
>
> So I want to use '$Id$' in my *.py files where '$Id$' got replaced  
> when I commit my files via svn.
>
> But I googled and I still couldn't make it work. Can somebody tell  
> to make it work? I would like to get at least date and time when  
> the files are committed ( svn on googlecode) in the file itself.
>
> Many thanks in advance.
>
> Alan
>
> -- 
> 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<<
>

Try this:

find . -name "*.py" -exec svn propset svn:keywords "Date" {} \;

> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



sites framework with multiple machines

2009-01-27 Thread David Lindquist

I have a client that maintains several hundred small web sites  
running on dozens of different machines all over the world. These  
sites have common data (footers, privacy policy pages, etc.) he would  
like to manage through a single CMS. Currently, he uploads all the  
changes manually using FTP. Yikes! The sites all run PHP, but my  
client has expressed interest in moving to Django eventually.

Would this be possible using Django's sites framework? I have not  
used the sites framework before, but on first read of the  
documentation, it seems that sites is restricted to a single Django  
installation with all the sites running on the same physical machine.  
Is that correct?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



list all context variables?

2009-01-14 Thread David Lindquist

Is there an easy way to see a list of all the context variables and  
their values available in a given template?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Where are all the Django jobs?

2009-01-12 Thread David Lindquist

Thank you Ashish, Malcolm, and Jon for your thorough and insightful  
answers.

On Jan 11, 2009, at 9:39 AM, Jon Loyens wrote:

>
> Django is starting to gain more traction and I do believe we'll start
> to see a bit more of a hockey stick effect on it's adoption over the
> coming months.  1.0 being released last year and (at least part-wise)
> adoption by the Google AppEngine have both been great PR events for
> Django but I'd also argue that Django doesn't have it's Twitter or
> BaseCamp yet i.e. a killer application that grabs the mindshare of
> startup CTO and CEOs that seemingly make them choose Rails.
>
> At Thinktiv, while we're a professional services company thats
> officially platform agnostic, we've chosen Django as our in-house
> framework of choice for development.  Django suits the majority of our
> customers applications very well (generally interesting presentations
> and visualization of structured data and media).  Whenever we've had
> customers where we get to influence the framework used, we'll sell
> Django into the account.  However, we've had customers comeback and
> want to build on Rails for the exact opposite reason from this thread:
> lack of people in the Austin area who know Python/Django to take on
> the maintenance work after we've done the initial application build.
> So it seems like we've got a bit of a chicken/egg problem.
>
> Our organization is going continue to evangelize Django in our
> community.  The more that the Django-community sells its virtues in
> our various consulting gigs the more opportunity we'll get to use the
> framework we love.  To further Malcolm's point above, be a good
> programmer first.  Good programmers should be able to pick up (or
> already know) multiple platforms, frameworks, languages quickly.
> Being a first rate programmer who's technology agnostic will open up a
> huge number of opportunities where you'll get to be the person who
> influences what gets used in various situations.  It's in those
> situations that you'll get to grab your favorite tool: Django.
>
> Jon Loyens
> Thinktiv, Inc.
>
> On Jan 11, 1:14 am, Malcolm Tredinnick 
> wrote:
>> On Sat, 2009-01-10 at 15:38 -0700, David Lindquist wrote:
>>> First, I understand that the world economy is in a slump, and that
>>> the job market as a whole has not fared well of late. But even  
>>> before
>>> the recent downturn, I noticed that there are precious few jobs in
>>> Django development (yes, I know about DjangoGigs.com). A simple
>>> keyword search on popular job boards shows that the number of  
>>> Ruby on
>>> Rails jobs outnumber Django easily by a factor of 10 or 20. True,
>>> Rails has been around longer, but not by much (a year maybe?).
>>
>>> So my question to the group is: if Rails has been widely adopted in
>>> the enterprise, why hasn't Django? Do you think Django will catch  
>>> on?
>>> Or do you think it will be more of a "boutique" framework?
>>
>> There are some slight problems with your methodology. Large companies
>> adopting something like Django aren't necessarily going to be  
>> posting to
>> djangogigs.com or places like that. They'll already have competent
>> programmers in-house to do the work. Or they'll hire through more
>> traditional channels. So it might well be that Django is more heavily
>> used in large organisations than Rails and all the Rails jobs you see
>> being advertised are because there are lots more gigs at the smaller
>> end.
>>
>> I have no evidence to support this either way, but it's always  
>> tough to
>> estimate "the number of people using X" by the job advertisements
>> without a lot more controlling of factors.
>>
>> It's probably a mistake to base your entire career for any period of
>> time on only doing Django work unless you have some long-term  
>> contract
>> or permanent position already lined up. But it's not a bad skill  
>> to have
>> in your bag of tools, since many other problems that contractors are
>> asked to solve can be solved using that particular skill. Keep in  
>> mind
>> that keyword searches only find offerings where the client/ 
>> employer has
>> already picked the solution and is trying to backfill a lack of  
>> skills
>> and hoping desperately that adding more people or bringing in new  
>> people
>> won't make things worse than they are (hiring contractors is very
>> risky). There are many other positions where the hirer is in a 

Where are all the Django jobs?

2009-01-10 Thread David Lindquist

First, I understand that the world economy is in a slump, and that  
the job market as a whole has not fared well of late. But even before  
the recent downturn, I noticed that there are precious few jobs in  
Django development (yes, I know about DjangoGigs.com). A simple  
keyword search on popular job boards shows that the number of Ruby on  
Rails jobs outnumber Django easily by a factor of 10 or 20. True,  
Rails has been around longer, but not by much (a year maybe?).

So my question to the group is: if Rails has been widely adopted in  
the enterprise, why hasn't Django? Do you think Django will catch on?  
Or do you think it will be more of a "boutique" framework?

I am perfectly open to the idea that my perceptions are way off or  
that I am being unrealistic or impatient. But I would really like to  
escape PHP-land someday.

Someone give me hope, please? :)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Returning large files from a view

2009-01-07 Thread David Lindquist


On Jan 7, 2009, at 4:15 PM, bruno desthuilliers wrote:

>
> On 7 jan, 23:37, David Lindquist  wrote:
>> I would like to return a binary file from a view, and so far I have
>> something like this:
>>
>> def my_file(request):
>>  file_data = open("/path/to/file", "rb").read()
>>  response =  HttpResponse(file_data, mimetype="application/
>> whatever")
>>  response['Content-Disposition'] = 'attachment; filename=my_file'
>>  return response
>>
>> Is there a better way to do this, especially for very large (> 10MB)
>> files?
>
> Do you have any reason to serve these files thru django instead of
> letting your frontal web server handle them ?.

The files do not reside under our site's document root, because my  
boss does not want them there (for reasons that aren't entirely clear  
to me). Also, we want to do some extra processing before the file is  
served, e.g. increment an integer representing the number of  
downloads. Thirdly, we want to be able to force the browser to  
download the file instead of displaying it (in the case of PDFs, for  
example).

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Returning large files from a view

2009-01-07 Thread David Lindquist

I would like to return a binary file from a view, and so far I have  
something like this:

def my_file(request):
 file_data = open("/path/to/file", "rb").read()
 response =  HttpResponse(file_data, mimetype="application/ 
whatever")
 response['Content-Disposition'] = 'attachment; filename=my_file'
 return response

Is there a better way to do this, especially for very large (> 10MB)  
files?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: order by field length?

2008-12-16 Thread David Lindquist

Perfect. Exactly what I needed.

Thank you Russ

On Dec 16, 5:22 pm, "Russell Keith-Magee" 
wrote:
> On Wed, Dec 17, 2008 at 9:04 AM, David Lindquist
>
>  wrote:
>
> > I encountered a scenario where I need to query the database for a
> > list of names sorted by length. In SQL this is easy:
>
> > SELECT name from distributors_distributor ORDER BY LENGTH(name)
>
> > Instead of writing raw SQL in my view, I am doing this:
>
> > names = [x['name'] for x in Distributor.objects.values('name')]
> > names.sort(lambda x, y: len(x) - len(y))
>
> > Is there a better way of doing this? Or rather, is there a way to use
> > the QuerySet API to produce the equivalent of the SQL above?
>
> Something like this should work:
>
> Distributor.objects.extra(select={'length':'Length(name)'}).order_by('lengt 
> h')
>
> This uses an extra() clause to add a length field to the select that
> is being retrieved, then uses that length column for sorting purposes.
> It does involve a little raw SQL leaking through to your code (the
> call to Length()), but not as much as a completely raw SQL query would
> require.
>
> This class of problem could also be addressed by the F() notation that
> has been proposed in #7210 and accepted for v1.1. This particular use
> case wasn't on the original todo list, but it should be in the realms
> of possibility.
>
> Yours,
> Russ Magee %-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



order by field length?

2008-12-16 Thread David Lindquist

I encountered a scenario where I need to query the database for a  
list of names sorted by length. In SQL this is easy:

SELECT name from distributors_distributor ORDER BY LENGTH(name)

Instead of writing raw SQL in my view, I am doing this:

names = [x['name'] for x in Distributor.objects.values('name')]
names.sort(lambda x, y: len(x) - len(y))

Is there a better way of doing this? Or rather, is there a way to use  
the QuerySet API to produce the equivalent of the SQL above?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: No documentation link on admin interface.

2008-12-12 Thread David Lindquist

On Dec 12, 2008, at 5:05 PM, waltbrad wrote:

>
> I'm using 1.0  -- I keep reading that there is supposed to be one in
> the upper right hand corner.  I finally had to use Google images to
> find an illustration.
>
> But I don't have that link displayed.  I do have the "change
> password / logout" links, but not the doc link.
>
> Can anybody throw me a hint?
>
> Thanks.

The admin documentation requires docutils to be installed.

http://docutils.sourceforge.net/

> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generate a simple news archive list?

2008-12-10 Thread David Lindquist

Perfect! I can't believe I overlooked that in the documentation.

Thanks Brian

On Dec 10, 2:15 pm, Brian Neal <[EMAIL PROTECTED]> wrote:
> On Dec 10, 2:31 pm, David Lindquist <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hello,
> > I am building a simple news app for my employer's website. I am using
> > Django's date-based generic views for the various pages. I want to
> > have a sidebar listing the archive by year and month like this:
>
> > 2008
>
> > - November
> > - December
>
> > 2009
>
> > - January
>
> > with each item linking to its view (year, month)
>
> > I have seen this a thousand times on websites, and it seems like it
> > should be a fairly easy thing to accomplish. But I can't figure out
> > how to craft a QuerySet to give me what I want. I suspect I need to
> > use {% regroup %} in the template as well. I just can't put it all
> > together.
>
> > Can someone point me in the right direction?
>
> Just what the doctor ordered:
>
> http://docs.djangoproject.com/en/dev/ref/models/querysets/#dates-fiel...
>
> Regards,
> BN

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



Generate a simple news archive list?

2008-12-10 Thread David Lindquist

Hello,
I am building a simple news app for my employer's website. I am using
Django's date-based generic views for the various pages. I want to
have a sidebar listing the archive by year and month like this:

2008

- November
- December

2009

- January

with each item linking to its view (year, month)

I have seen this a thousand times on websites, and it seems like it
should be a fairly easy thing to accomplish. But I can't figure out
how to craft a QuerySet to give me what I want. I suspect I need to
use {% regroup %} in the template as well. I just can't put it all
together.

Can someone point me in the right direction?

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