Re: How to locate the OS user name? [newbie]

2010-03-25 Thread BobAalsma
In addition:
So maybe Baurzhan was right: using a database login (explicit or
implicit) could be the easier solution to build.

Regards,
Bob

On Mar 26, 7:32 am, BobAalsma  wrote:
> Hmm, on second thoughts...
>
> I tested from the shell in a few user environements and it worked.
>
> However, when applying this to Django, all users show the user name of
> the user running the server.
>
> Hindsight makes this logical, as the other users only use their
> browser, not their own local python.
>
> So I think now the question seems to be "how to extract the OS user
> name from the browser environment?"
>
> Regards,
> Bob
>
> On Mar 25, 7:06 pm, BobAalsma  wrote:
>
> > OK, found it - thanks!
>
> > Regards,
> > Bob
>
> > On Mar 25, 6:40 pm, "piz...@gmail.com"  wrote:
>
> > > Check the module index in the python website:http://docs.python.org/
> > > modindex.html
>
> > > There you will find everything about python modules like sys, os, and  
> > > others.
>
> > > Regards,
> > > Oscar C.
>
> > > El 25/03/2010, a las 18:28, BobAalsma escribió:
>
> > > > YES!
>
> > > > Works beautifully, thanks.
>
> > > > On the newbie part: how could I have found this?
> > > > I did find the os.environ and you've helped me discover how to look
> > > > inside, but what if I need something completely different?
>
> > > > Regards,
> > > > Bob

-- 
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: How to locate the OS user name? [newbie]

2010-03-25 Thread BobAalsma
Hmm, on second thoughts...

I tested from the shell in a few user environements and it worked.

However, when applying this to Django, all users show the user name of
the user running the server.

Hindsight makes this logical, as the other users only use their
browser, not their own local python.

So I think now the question seems to be "how to extract the OS user
name from the browser environment?"

Regards,
Bob


On Mar 25, 7:06 pm, BobAalsma  wrote:
> OK, found it - thanks!
>
> Regards,
> Bob
>
> On Mar 25, 6:40 pm, "piz...@gmail.com"  wrote:
>
> > Check the module index in the python website:http://docs.python.org/
> > modindex.html
>
> > There you will find everything about python modules like sys, os, and  
> > others.
>
> > Regards,
> > Oscar C.
>
> > El 25/03/2010, a las 18:28, BobAalsma escribió:
>
> > > YES!
>
> > > Works beautifully, thanks.
>
> > > On the newbie part: how could I have found this?
> > > I did find the os.environ and you've helped me discover how to look
> > > inside, but what if I need something completely different?
>
> > > Regards,
> > > Bob

-- 
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: How to locate the OS user name? [newbie]

2010-03-25 Thread BobAalsma
Hmm, on second thoughts...

I tested from the shell in a few user environements and it worked.

However, when applying this to Django, all users show the user name of
the user running the server.

Hindsight makes this logical, as the other users only use their
browser, not their own local python.

So I think now the question seems to be "how to extract the OS user
name from the browser environment?"

Regards,
Bob


On Mar 25, 7:06 pm, BobAalsma  wrote:
> OK, found it - thanks!
>
> Regards,
> Bob
>
> On Mar 25, 6:40 pm, "piz...@gmail.com"  wrote:
>
> > Check the module index in the python website:http://docs.python.org/
> > modindex.html
>
> > There you will find everything about python modules like sys, os, and  
> > others.
>
> > Regards,
> > Oscar C.
>
> > El 25/03/2010, a las 18:28, BobAalsma escribió:
>
> > > YES!
>
> > > Works beautifully, thanks.
>
> > > On the newbie part: how could I have found this?
> > > I did find the os.environ and you've helped me discover how to look
> > > inside, but what if I need something completely different?
>
> > > Regards,
> > > Bob

-- 
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: problems with get_or_create

2010-03-25 Thread Kenneth Gonsalves
On Thursday 25 Mar 2010 9:17:12 pm Malcolm Tredinnick wrote:
> I don't understand what you are saying here. If the instance exists (as
> in, the filter parameters passed to get would return a single item),
> that instance is returned and the default parameters are never
> considered. So the values you pass for slno and mode are irrelevant. If
> the equivalent get() call would not return anything, then the instance
> does not exist and it's clear that the default parameter must contain
> correct data that can be used to create a new object -- including not
> violating any unique constraints. Perhaps you could show the code call
> you are making, rather than writing it out as a sentence.
> 
> In short: get_or_create() first runs the get(). If that returns
> something, it is what is returned. If the get() fails with no object
> being present, then the instance DOES NOT exist and a new one is
> created, with all the same requirements as if you'd created a new object
> from scratch (e.g. no unique constraint violations).
> 

sorry for not replying to this - for some reason all your recent mails have 
gone to the spam folder! I only became aware of this mail when I saw a reply 
to it. Here is what I mean - A simple model with two fields, 'name' is unique, 
and 'num' is not null:

>>> Tm.objects.get_or_create(name='me',num=1)   
>>>   
(, True)
  
>>> Tm.objects.get_or_create(name='me',num=2)   
>>>  
Traceback (most recent call last):  
 
  File "", line 1, in  
 
  File "/usr/lib/python2.6/django/db/models/manager.py", line 135, in 
get_or_create  
return self.get_query_set().get_or_create(**kwargs) 
 
  File "/usr/lib/python2.6/django/db/models/query.py", line 375, in 
get_or_create
transaction.savepoint_rollback(sid, using=self.db)  
 
  File "/usr/lib/python2.6/django/db/transaction.py", line 242, in 
savepoint_rollback
connection._savepoint_rollback(sid) 
 
  File "/usr/lib/python2.6/django/db/backends/__init__.py", line 61, in 
_savepoint_rollback  
self.cursor().execute(self.ops.savepoint_rollback_sql(sid))
  File "/usr/lib/python2.6/django/db/backends/__init__.py", line 75, in cursor
cursor = self._cursor()
  File "/usr/lib/python2.6/django/db/backends/postgresql/base.py", line 149, 
in _cursor
cursor.execute("SET client_encoding to 'UNICODE'")
ProgrammingError: ERROR:  current transaction is aborted, commands ignored 
until end of transaction block

SET client_encoding to 'UNICODE'
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS
http://certificate.nrcfoss.au-kbc.org.in

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

2010-03-25 Thread Asim Yuksel
I cant show the foreignkey values in a list_display. I tried
raw_id_fields but didnt work

On 25 Mart, 23:18, Shawn Milochik  wrote:
> This should help:
>
> http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#raw-id-fields
>
> Shawn

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



Using ModelForm to edit ManyToMany in both directions?

2010-03-25 Thread Wilberoni
I have a simple model that allows a volunteer to have many jobs and a
job to have many volunteers:

class Volunteer(models.Model):
jobs = models.ManyToManyField( 'Job', blank=True )


The following ModelForm displays a Multi-select widget so I can choose
all the jobs for a volunteer:

class VolunteerForm( ModelForm ):

class Meta:
model = Volunteer


This is some fairly basic Django.  However, I'd also like to be able
to edit in the other direction -- from a Jobs form, I'd like to be
able to see a Multi-select widget containing all the volunteers who
have this job and select/unselect them.  I can't quite wrap my brain
around this and I've found no clues by searching the web.  Does Django
provide some facility to accomplish this or do I have to build
something from the ground up?

Thanks.
Wilb

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

2010-03-25 Thread Shawn Milochik
This should help:

http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#raw-id-fields

Shawn

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



ForeignKeyField

2010-03-25 Thread Asim Yuksel
I have a question about model.ForeignKey field.Foreign key fields are
shown as object in admin page. How can I show them in other types like
integer type
for example I have a Model like this:

class Advisor(models.Model):

advisorid = models.IntegerField(primary_key=True,
db_column='advisorId')
maphdid = models.ForeignKey(Tblmaphds, db_column='maPhDId')
def __str__(self):
return smart_str('%s' % (self.maphdid))
def __unicode__(self):
return smart_str('%s' % (self.maphdid))
class Meta:
db_table = 'Advisor'

The problem is I see the maphdid value as "Tblmaphds object" instead
of a normal integer value.

What should I do to see a integer value?

-- 
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: Project optimisation stage: Advice to boost speed of database queries across tables?

2010-03-25 Thread Sam Walters
I also read a good article. As it turns out im using a lot of inner joins:

http://www.caktusgroup.com/blog/2009/09/

This  was quite handy.
My processis usually build it to be as fast as possible in raw SQL
then go back in and try and makre it with the ORM.

"I've read your description and it doesn't mention how often your data
changes. If it's not too often, you might want to consider simply
caching the whole results or parts of it. You'll then have to add a
bit of code to regenerate the cache every time the data changes."

Yes actually in some of the scenarios the data is quite static,
however im doing a lot of stuff with lat/long coordinates now so it
means i have a bunch of keys in the results dict returned which are
all dynamic, per click values and need to be recalculated a lot.
Note: I have taken your advice on board for some of my views Philippe.

Cheers

Sam_W


On Fri, Jan 8, 2010 at 12:18 AM, Philippe Raoult
 wrote:
> Hi Sam,
>
> I've read your description and it doesn't mention how often your data
> changes. If it's not too often, you might want to consider simply
> caching the whole results or parts of it. You'll then have to add a
> bit of code to regenerate the cache every time the data changes. It
> looks to me like you have one query for selecting which entries to
> print, then many repetitive queries to find information about each
> entry. If you had a per-entry cache then you would probably be down to
> one main query plus a lot of cache lookups.
>
> Also you were on the right track when using addresses =
> Address.objects.filter(directory__in=directories). I've often used
> that kind of queries to reduce (1 + many queries) down to (2 + lots of
> dictionnary operations)
>
> Hope that helps.
>
> Regards,
> Philippe
>
>
> On 7 jan, 11:39, Sam Walters  wrote:
>> Thanks Koen
>> I had suspected such things would exist but couldnt find them.
>> I will take a look at this. Looks like a neat addon which would
>> greatly help my project turnaround time.
>>
>> cheers
>> Sam
>>
>> On Wed, Jan 6, 2010 at 11:07 PM, koenb  wrote:
>>
>> > On 31 dec 2009, 01:56, Sam Walters  wrote:
>> >> Thanks for the replies.
>>
>> >> Yes, there is the option of going to raw MySQL. However the project
>> >> requirements mean i can't use raw SQL. (portability, readability)
>> >> From what i can see using django's db API i have to execute the
>> >> queries 500 times.
>> >> I am very familiar with the query documentation and i know that
>> >> select_related will prevent foward facing foreign keys translating to
>> >> an individual sql queries which hit the db and would slow it down.
>>
>> >> Fact is even when i dont use 'select_related' the major performance
>> >> problem occurs with the 'many-to-many' and 'reverse foreign' keys
>> >> (some 75% of the performance penalty for my package method is with
>> >> these) and only 20% can be solved by select_related.
>>
>> >> To be specific about how the multiplicities unfold:
>>
>> >> search_querySet is a Directory.objects.filter(...
>>
>> >> for s in search_querySet:
>> >>         address_info = s.address_set.all() #.select_related(depth=2) -
>> >> yes i can/will put select related here but it really does not help
>> >> that much 20% tops
>> >>         #address_info is usually 2-3 rows from an address table
>> >>         for a in address_info:#.select_related(depth=2):
>> >>             if a.addresstype.adrtype == 'Physical' and
>> >> a.addradmin.addr_enabled == True:
>> >>             #further reduction in the number of rows which we need to
>> >> get values from.
>> >>             related_phone=a.phone_set.all()
>> >>             related_email=s.email_set.all()
>> >>             #phones and emails are a small number of rows 2-3 tops
>>
>> >> It is these lines which produce the performance hit.
>> >> I cant see a way of using django's query language to avoid having to
>> >> descend into each of the 500 'directory' objects because of the
>> >> necessity to get all rows from the related tables in phones an emails
>> >> and to inspect the type of 'address' object.
>>
>> >> thanks for the ideas. will continue testing and looking for answers
>>
>> >> -Sam
>>
>> >> On Thu, Dec 31, 2009 at 2:41 AM, Nick Arnett  
>> >> wrote:
>>
>> >> > On Wed, Dec 30, 2009 at 7:15 AM, Adam Playford 
>> >> > wrote:
>>
>> >> >> I'm not an expert on this, but a few thoughts.
>>
>> >> >> First, if I'm reading your message right, it sounds like your problem
>> >> >> probably isn't with the query, but with how many times you're running
>> >> >> it.
>>
>> >> > I'll echo that... the problem is not the database - the queries are as 
>> >> > good
>> >> > as it gets.  The problem is running them repeatedly.
>>
>> >> > If all else fails, I'd replace those queries that execute 500 times 
>> >> > with raw
>> >> > SQL that uses the IN operator to get the required rows.
>>
>> >> > E.g.: SELECT `common_addresstype`.`id`, `common_addresstype`.`adrtype` 
>> >> > FROM
>> >> > `common_addresstype` WHERE `common_addresst

Any way to have a ModelForm tied to 2 Models?

2010-03-25 Thread Continuation
I have 2 models: A, B

I need a form that inserts/updates both fields of A and fields of B.

Is there any way to create a ModelForm tied to A & B? Or do I need to
use the plain old Form?

-- 
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: syncdb error for models pointing to each other

2010-03-25 Thread Dries Desmet
On 26 March 2010 01:11, Ramiro Morales  wrote:

> On Thu, Mar 25, 2010 at 9:03 PM, Dries Desmet  wrote:
> > My models are:
> >
> > 
> > class Album(models.Model):
> > slug = models.SlugField(
> > unique=True,
> > help_text=_("Suggested value automatically generated from title.
> > Must be unique.")
> > )
> > # using name of the model, rather than the model object itself,
> > # because Photo is not yet defined.
> > cover_image = models.ForeignKey('Photo', blank=True, null=True)
> >
> > class Image(models.Model):
> > album = models.ForeignKey('Album', related_name='images')
> > image =
> > ImageWithThumbnailsField(upload_to='upload/mygallery/images/%Y/%m/%d/',
> >  thumbnail={'size':
> > settings.MYGALLERY_THUMBNAILSIZE})
> > ---
> > But doing python manage.py syncdb states:
> > "mygallery.album: 'cover_image' has a relation with model Photo, which
> has
> > either not been installed or is abstract."
> >
> > As stated in the django model reference, I'm already using the Foreignkey
> > field with a name (string) rather than the model itself. I'm using
> > Postgresql. What am I missing? Are 2 models not allowed to point to each
> > other?
>
> Re-read the error message, it is correctly pointing the problem.
>
> You don't seem to have any model called Photo, at least no
> in the code you included in you email.
>
> --
> Ramiro Morales  |  http://rmorales.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-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.
>
>
OMG, thank you Ramiro. I had changed Photo to Image because I thought it was
going to be more appropriate. This one slipped through. Thank you so much
for extra pair of eyes, although I have to admit, mine were very muddy
today.

-- 
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: syncdb error for models pointing to each other

2010-03-25 Thread Ramiro Morales
On Thu, Mar 25, 2010 at 9:03 PM, Dries Desmet  wrote:
> My models are:
>
> 
> class Album(models.Model):
>     slug = models.SlugField(
>     unique=True,
>     help_text=_("Suggested value automatically generated from title.
> Must be unique.")
>     )
>     # using name of the model, rather than the model object itself,
>     # because Photo is not yet defined.
>     cover_image = models.ForeignKey('Photo', blank=True, null=True)
>
> class Image(models.Model):
>     album = models.ForeignKey('Album', related_name='images')
>     image =
> ImageWithThumbnailsField(upload_to='upload/mygallery/images/%Y/%m/%d/',
>  thumbnail={'size':
> settings.MYGALLERY_THUMBNAILSIZE})
> ---
> But doing python manage.py syncdb states:
> "mygallery.album: 'cover_image' has a relation with model Photo, which has
> either not been installed or is abstract."
>
> As stated in the django model reference, I'm already using the Foreignkey
> field with a name (string) rather than the model itself. I'm using
> Postgresql. What am I missing? Are 2 models not allowed to point to each
> other?

Re-read the error message, it is correctly pointing the problem.

You don't seem to have any model called Photo, at least no
in the code you included in you email.

-- 
Ramiro Morales  |  http://rmorales.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-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.



syncdb error for models pointing to each other

2010-03-25 Thread Dries Desmet
My models are:


class Album(models.Model):
slug = models.SlugField(
unique=True,
help_text=_("Suggested value automatically generated from title.
Must be unique.")
)
# using name of the model, rather than the model object itself,
# because Photo is not yet defined.
cover_image = models.ForeignKey('Photo', blank=True, null=True)

class Image(models.Model):
album = models.ForeignKey('Album', related_name='images')
image =
ImageWithThumbnailsField(upload_to='upload/mygallery/images/%Y/%m/%d/',
 thumbnail={'size':
settings.MYGALLERY_THUMBNAILSIZE})
---
But doing python manage.py syncdb states:
"mygallery.album: 'cover_image' has a relation with model Photo, which has
either not been installed or is abstract."

As stated in the django model reference, I'm already using the Foreignkey
field with a name (string) rather than the model itself. I'm using
Postgresql. What am I missing? Are 2 models not allowed to point to each
other?

Regards.
Dries.

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



Passing context variables from template to view

2010-03-25 Thread Kasto
Hi,

I am looking to implement an "Export to Excel sheet" feature. The
result-set is already available and rendered in the template. I need
to provide a link or button to export result to Excel sheet.

Result-set is a set of list variables and cannot be passed over GET
request due to length limitations.

Two solutions that I can think of are:

1. Use hidden form fields and submit it back to a view that creates
Excel sheet.
2. Directly pass object list to view using reverse() or URL regex.

I have been unable to pass lists using URL Regex. Is it possible to
pass list variables from template back to the view? If so, how?


Appreciate ur help!

Kasto
--

-- 
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: Multiple querysets for dictionary

2010-03-25 Thread pakalk


On 25 Mar, 17:27, grimmus  wrote:
> Hi,
>
> For my xml sitemap i would like to show blog posts and pages from the
> CMS. How can i pass 2 querysets to the dictionary ?
>
> What i have so far is below, it's obviously wrong :-(
>
> info_dict = {
>     'queryset': Page.objects.filter(active=1),
>     'queryset': Entry.objects.filter(status=1),
>     'date_field': 'pub_date',
>
> }
>
> Thanks for any help


You can use one key twice. Wow. Respect.

-- 
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: About extending User model

2010-03-25 Thread Jim N
Hi Peter,

I'm building an app where all logged-in users will be a Django user,
rather than creating some new separate class of users just for my own
app.

But to make it work, these users have to have more than the minimal
information contained in the django.contrib.auth.models User.  I
figure that's a fairly common situation.

I may create one class of users through Django's built-in admin.
Another class will be created via an API interface to my app.  In each
case, they need lots of detail missing from User.

Is my solution to create the User and update the profile separately
every time?  I can accept that it is, but was just looking for a more
tightly-coupled solution for extending the built-in user.

For example, I can't use django.contrib.auth.models User as a foreign
key in my models.  So how would I link a model instance (row) to a
user?  This is a question and answer site, so Answer would have a
foreign key of User, except that doesn't work.

Apologies if this is all spelled out somewhere and I just haven't
found it.

-Jim

On Mar 25, 5:18 pm, Peter Bengtsson  wrote:
> Generally, try to build your application so that it doesn't blindly
> depend on the profile existing. The signal example Tom showed you is
> good as it means you won't have to check if the UserProfile instance
> exists for the user on every turn. However, don't depend on the data
> within. Keep it light and separate.
> Why does the admin need the stuff you can put in UserProfile if you
> create him via the admin pages?
> If he really needs it, tell him to register and then you go in an turn
> his created account (in the admin) to a superuser or whatever you
> need.
>
> On 25 Mar, 18:37, Jim N  wrote:
>
>
>
> > On Mar 11, 1:03 pm, Tom Evans  wrote:
>
> > > On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  
> > > wrote:
> > > > I'm using UserProfile to add one field to my users. However, I know
> > > > that I must explicitly create UserProfile for each new user that
> > > > registers. So, I make a UserProfile upon registration. Is UserProfile
> > > > still the best way to extend the user model?
> > > > What about the admin user, or users that the admin creates? Since they
> > > > don't go through the registration process, how do I ensure that their
> > > > UserProfile gets created?
>
> > > Add this to your models.py
>
> > > from django.db.models.signals import post_save
> > > from django.contrib.auth.models import User
>
> > > def _hook_save_user(instance, sender, **kwargs):
> > >   try:
> > >     instance.get_profile()
> > >   except UserProfile.DoesNotExist:
> > >     UserProfile.objects.get_or_create(user=instance)
>
> > > post_save.connect(_hook_save_user, sender=User)
>
> > On Mar 11, 1:03 pm, Tom Evans  wrote:
>
> > > On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  
> > > wrote:
> > > > I'm using UserProfile to add one field to my users. However, I know
> > > > that I must explicitly create UserProfile for each new user that
> > > > registers. So, I make a UserProfile upon registration. Is UserProfile
> > > > still the best way to extend the user model?
> > > > What about the admin user, or users that the admin creates? Since they
> > > > don't go through the registration process, how do I ensure that their
> > > > UserProfile gets created?
>
> > > Add this to your models.py
>
> > > from django.db.models.signals import post_save
> > > from django.contrib.auth.models import User
>
> > > def _hook_save_user(instance, sender, **kwargs):
> > >   try:
> > >     instance.get_profile()
> > >   except UserProfile.DoesNotExist:
> > >     UserProfile.objects.get_or_create(user=instance)
>
> > > post_save.connect(_hook_save_user, sender=User)
>
> > Very interesting, Tom.
>
> > I have inserted this code, substituting my profile model name
> > (QotdUser) for UserProfile.  It does create a row in QotdUser, but the
> > row is empty of course.
>
> > More importantly, if I create a user via the admin interface (http://
> > 127.0.0.1:8000/admin/auth/user/add/) there's no apparent way to edit
> > any of the fields of my profile model.
>
> > Or if I create the user some other way, would I be able to pass
> > arguments to the User model to populate the profile?
>
> > Finally, how do I access the profile, is it like
>
> >   my_user_profile = User.objects.get(username="jim").get_profile() ?
>
> > Thanks for the help.
>
> > -Jim

-- 
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: Nested for loop: {% cycle ... %}

2010-03-25 Thread Bill Freeman
As I understand it, {{ foo }} renders the current value of the
variable and doesn't change it.
{% cycle foo %} or the creating {% cycle "odd" "even" as foo %}
advance the variable and
then render it.  So you still need one of the latter in your loop, or
the variable won't advance.

On Thu, Mar 25, 2010 at 5:43 PM, mhulse  wrote:
> Hi Peter and Bill! Thanks for the quick replies, I really appreciate
> it. :)
>
> @Peter:
>
> I tried this:
>
> ==
>
> {% for foo, baz in tuple %}
> ...
> 
> ...
> {% cycle "odd" "even" as foo %}
> {% for bar in baz %}
> ...
> ...
> {% endfor %}
> ...
> 
> ...
> {% endfor %}
>
> ==
>
> But the cycle "renders" the output and the variable "foo" does this:
>
> ==
>
> ..
> ..
> ...
>
> ==
>
> Maybe I am not understanding the usage of the "as" part?
>
> @Bill:
>
> Ahhh! Hehe, that is tricky. :D
>
> I will experiment with your code sample.
>
> ...
>
> It just came to me... I can use "divisibleby"!
>
> This works:
>
> ==
>
>  endif %}">
>
> ==
>
> Django's version of the PHP modulo operator strikes again!
>
> Thanks again Peter and Bill, I really appreciate the help. Thanks for
> taking the time to help a noob out. :D
>
> Cheers,
> Micky
>
> --
> 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.
>
>

-- 
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: Nested for loop: {% cycle ... %}

2010-03-25 Thread mhulse
> As I understand it, {{ foo }} renders the current value of the
> variable and doesn't change it.
> {% cycle foo %} or the creating {% cycle "odd" "even" as foo %}
> advance the variable and
> then render it.  So you still need one of the latter in your loop, or
> the variable won't advance.

Ahhh! I get it! :)

Thanks Bill! I really appreciate the clarification.

Have an excellent day.

Cheers,
Micky

-- 
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: Nested for loop: {% cycle ... %}

2010-03-25 Thread mhulse
Hi Peter and Bill! Thanks for the quick replies, I really appreciate
it. :)

@Peter:

I tried this:

==

{% for foo, baz in tuple %}
...

...
{% cycle "odd" "even" as foo %}
{% for bar in baz %}
...
...
{% endfor %}
...

...
{% endfor %}

==

But the cycle "renders" the output and the variable "foo" does this:

==

..
..
...

==

Maybe I am not understanding the usage of the "as" part?

@Bill:

Ahhh! Hehe, that is tricky. :D

I will experiment with your code sample.

...

It just came to me... I can use "divisibleby"!

This works:

==



==

Django's version of the PHP modulo operator strikes again!

Thanks again Peter and Bill, I really appreciate the help. Thanks for
taking the time to help a noob out. :D

Cheers,
Micky

-- 
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: Nested for loop: {% cycle ... %}

2010-03-25 Thread Bill Freeman
On Thu, Mar 25, 2010 at 3:57 PM, mhulse  wrote:
> Hi!
>
> Example code:
>
> ==
>
> {% for pretty_date, days_events in date_days_events_tuple %}
> ...
> 
> ...
> {% for details in days_events %}
> ...
> ...
> {% endfor %}
> ...
> 
> ...
> {% endfor %}
>
> ==
>
> The output:
>
> ==
>
> ..
> ..
> ...
>
> ==
>
> What I really want:
>
> ==
>
> ..
> ..
> ...
>
> ==
>
> This must be a complete noob question. Sorry 'bout that. :D
>
> Thanks!
> Micky

You might be able to use the {% cycle "odd" "even" as variable %} form and then,
after your first endfor:



I *think* that you want "odd" in the ifequal.  Looking at the render
code, the variable appears
to be left in the state that was last rendered.  So, if when you look
at it it is "odd" then the
next rendering would be "even", so we do an extra cycle in this case,
making "odd" be
next, for the first cycle in the next run of the inner loop.  But if
it doesn't work, try "even".

There may be a more elegant way to eat the extra rendering than the
html comment, but
I can't think of it off hand.

Bill

-- 
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: About extending User model

2010-03-25 Thread Peter Bengtsson
Generally, try to build your application so that it doesn't blindly
depend on the profile existing. The signal example Tom showed you is
good as it means you won't have to check if the UserProfile instance
exists for the user on every turn. However, don't depend on the data
within. Keep it light and separate.
Why does the admin need the stuff you can put in UserProfile if you
create him via the admin pages?
If he really needs it, tell him to register and then you go in an turn
his created account (in the admin) to a superuser or whatever you
need.

On 25 Mar, 18:37, Jim N  wrote:
> On Mar 11, 1:03 pm, Tom Evans  wrote:
>
> > On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  
> > wrote:
> > > I'm using UserProfile to add one field to my users. However, I know
> > > that I must explicitly create UserProfile for each new user that
> > > registers. So, I make a UserProfile upon registration. Is UserProfile
> > > still the best way to extend the user model?
> > > What about the admin user, or users that the admin creates? Since they
> > > don't go through the registration process, how do I ensure that their
> > > UserProfile gets created?
>
> > Add this to your models.py
>
> > from django.db.models.signals import post_save
> > from django.contrib.auth.models import User
>
> > def _hook_save_user(instance, sender, **kwargs):
> >   try:
> >     instance.get_profile()
> >   except UserProfile.DoesNotExist:
> >     UserProfile.objects.get_or_create(user=instance)
>
> > post_save.connect(_hook_save_user, sender=User)
>
> On Mar 11, 1:03 pm, Tom Evans  wrote:
>
>
>
> > On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  
> > wrote:
> > > I'm using UserProfile to add one field to my users. However, I know
> > > that I must explicitly create UserProfile for each new user that
> > > registers. So, I make a UserProfile upon registration. Is UserProfile
> > > still the best way to extend the user model?
> > > What about the admin user, or users that the admin creates? Since they
> > > don't go through the registration process, how do I ensure that their
> > > UserProfile gets created?
>
> > Add this to your models.py
>
> > from django.db.models.signals import post_save
> > from django.contrib.auth.models import User
>
> > def _hook_save_user(instance, sender, **kwargs):
> >   try:
> >     instance.get_profile()
> >   except UserProfile.DoesNotExist:
> >     UserProfile.objects.get_or_create(user=instance)
>
> > post_save.connect(_hook_save_user, sender=User)
>
> Very interesting, Tom.
>
> I have inserted this code, substituting my profile model name
> (QotdUser) for UserProfile.  It does create a row in QotdUser, but the
> row is empty of course.
>
> More importantly, if I create a user via the admin interface (http://
> 127.0.0.1:8000/admin/auth/user/add/) there's no apparent way to edit
> any of the fields of my profile model.
>
> Or if I create the user some other way, would I be able to pass
> arguments to the User model to populate the profile?
>
> Finally, how do I access the profile, is it like
>
>   my_user_profile = User.objects.get(username="jim").get_profile() ?
>
> Thanks for the help.
>
> -Jim

-- 
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: Nested for loop: {% cycle ... %}

2010-03-25 Thread Peter Bengtsson
Is it possible to do
{% cycle "odd" "even" as parent_cycle_thing %}
?
If so there's your answer.

On 25 Mar, 19:57, mhulse  wrote:
> Hi!
>
> Example code:
>
> ==
>
> {% for pretty_date, days_events in date_days_events_tuple %}
> ...
> 
> ...
> {% for details in days_events %}
> ...
> ...
> {% endfor %}
> ...
> 
> ...
> {% endfor %}
>
> ==
>
> The output:
>
> ==
>
> ..
> ..
> ...
>
> ==
>
> What I really want:
>
> ==
>
> ..
> ..
> ...
>
> ==
>
> This must be a complete noob question. Sorry 'bout that. :D
>
> Thanks!
> Micky

-- 
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: auto authenticate

2010-03-25 Thread Peter Bengtsson
If what you want to achieve is to log in a user programmatically you
don't do that by authenticating by username and password.
Example:


def login_by_id(request):

   user = FacebookUser.objects.get(...).user

   from django.contrib.auth import load_backend, login
   for backend in settings.AUTHENTICATION_BACKENDS:
if user == load_backend(backend).get_user(user.pk):
user.backend = backend
   if hasattr(user, 'backend'):
 login(request, user)


On 25 Mar, 18:27, CrabbyPete  wrote:
> I am connecting facebook to an app I have running. In order not to
> change a load of code I created a dummy account when someone logs in
> through facebook. My only problem is I want to authenticate with this
> account when they log  Is there a way to login in a user using the
> encrypted password. I am using pyfacebook and FacebookUser is the
> following model
>
> class FacebookUser(models.Model):
>     user            = models.ForeignKey(User, unique = True)
>     fb_uid          = models.CharField( max_length=100, blank = True,
> unique = True)
>
>     def __unicode__(self):
>         if self.user.username == u'':
>             return str(self.pk)
>         return self.user.username
>
> the fb_uid is the Facebook id I get back. Here is my view when I get
> called from facebook
>
> fb = request.facebook
>  try:
>       fid = FacebookUser.objects.get(Q(fb_uid = fb.uid))
> except FacebookUser.DoesNotExist:
>        return ...
>
> name = fid.user
> pswd = fid.user.password
> user = auth.authenticate(username=name, password=pswd)
>  if user is not None and user.is_active:
>      auth.login(request, user)
>
> pswd is an encrypted password. Is there a way for me to authenticate
> with 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-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.



Nested for loop: {% cycle ... %}

2010-03-25 Thread mhulse
Hi!

Example code:

==

{% for pretty_date, days_events in date_days_events_tuple %}
...

...
{% for details in days_events %}
...
...
{% endfor %}
...

...
{% endfor %}

==

The output:

==

..
..
...

==

What I really want:

==

..
..
...

==

This must be a complete noob question. Sorry 'bout that. :D

Thanks!
Micky

-- 
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: Initial data in a many to many field

2010-03-25 Thread mjlissner
I wasn't using ProfileForm(instance = userProfile) because I didn't
realize I could. Wow, that makes things easier and neater.

Thanks so much.

On Mar 25, 11:57 am, Nuno Maltez  wrote:
> >On Thu, Mar 25, 2010 at 2:00 AM, mjlissner  wrote:
> > I'll make things more concrete. I have the following in my model
> > (which is made into a ModelForm):
> > class UserProfile(models.Model):
> >    barmembership = models.ManyToManyField(BarMembership,
> >        verbose_name="the bar memberships held by the user",
> >        blank=True,
> >        null=True)
>
> > In my view, I have some code that looks like this:
> >        userProfile = request.user.get_profile()
> >        bar_memberships = userProfile.barmembership.all()
>
> >        profileForm = ProfileForm(
> >        initial = {'barmembership' : [bar_memberships]})
>
> I don't know why you're not using the "instance" argument to populate the form
>
> profileForm = ProfileForm(instance=userProfile)
>
> but you need to give the ModelForm a list of PKs for the many-to-many-field:
>
> bar_memberships = [obj.pk for obj in ob.barmembership.all()]
> profileForm = ProfileForm( initial = {'barmembership' : bar_memberships})
>
> (see the model_to_dict code in django/forms/models.py )
>
> And force the refresh on the browser if it looks like it's not working
> :) (at least FF has a strange
> habit of keeping selections when reloading a form, ignoring the
> initial selected items on the HTML).
>
> hth,
> Nuno

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



Grouped statements in debug_toolbar

2010-03-25 Thread Peter Bengtsson
The old django debug-toolbar used to make it possible to group
statements that were the same so you can see if a particular statement
was called repeatedly. This does not appear to be possible in the
latest version; or am I wrong?

-- 
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: Initial data in a many to many field

2010-03-25 Thread Nuno Maltez
>On Thu, Mar 25, 2010 at 2:00 AM, mjlissner  wrote:
> I'll make things more concrete. I have the following in my model
> (which is made into a ModelForm):
> class UserProfile(models.Model):
>    barmembership = models.ManyToManyField(BarMembership,
>        verbose_name="the bar memberships held by the user",
>        blank=True,
>        null=True)
>
> In my view, I have some code that looks like this:
>        userProfile = request.user.get_profile()
>        bar_memberships = userProfile.barmembership.all()
>
>        profileForm = ProfileForm(
>        initial = {'barmembership' : [bar_memberships]})


I don't know why you're not using the "instance" argument to populate the form

profileForm = ProfileForm(instance=userProfile)


but you need to give the ModelForm a list of PKs for the many-to-many-field:

bar_memberships = [obj.pk for obj in ob.barmembership.all()]
profileForm = ProfileForm( initial = {'barmembership' : bar_memberships})

(see the model_to_dict code in django/forms/models.py )

And force the refresh on the browser if it looks like it's not working
:) (at least FF has a strange
habit of keeping selections when reloading a form, ignoring the
initial selected items on the HTML).

hth,
Nuno

-- 
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: About extending User model

2010-03-25 Thread Jim N
On Mar 11, 1:03 pm, Tom Evans  wrote:
> On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  
> wrote:
> > I'm using UserProfile to add one field to my users. However, I know
> > that I must explicitly create UserProfile for each new user that
> > registers. So, I make a UserProfile upon registration. Is UserProfile
> > still the best way to extend the user model?
> > What about the admin user, or users that the admin creates? Since they
> > don't go through the registration process, how do I ensure that their
> > UserProfile gets created?
>
> Add this to your models.py
>
> from django.db.models.signals import post_save
> from django.contrib.auth.models import User
>
> def _hook_save_user(instance, sender, **kwargs):
>   try:
>     instance.get_profile()
>   except UserProfile.DoesNotExist:
>     UserProfile.objects.get_or_create(user=instance)
>
> post_save.connect(_hook_save_user, sender=User)
>
On Mar 11, 1:03 pm, Tom Evans  wrote:
> On Thu, Mar 11, 2010 at 4:54 PM, russianbandit  
> wrote:
> > I'm using UserProfile to add one field to my users. However, I know
> > that I must explicitly create UserProfile for each new user that
> > registers. So, I make a UserProfile upon registration. Is UserProfile
> > still the best way to extend the user model?
> > What about the admin user, or users that the admin creates? Since they
> > don't go through the registration process, how do I ensure that their
> > UserProfile gets created?
>
> Add this to your models.py
>
> from django.db.models.signals import post_save
> from django.contrib.auth.models import User
>
> def _hook_save_user(instance, sender, **kwargs):
>   try:
>     instance.get_profile()
>   except UserProfile.DoesNotExist:
>     UserProfile.objects.get_or_create(user=instance)
>
> post_save.connect(_hook_save_user, sender=User)
>

Very interesting, Tom.

I have inserted this code, substituting my profile model name
(QotdUser) for UserProfile.  It does create a row in QotdUser, but the
row is empty of course.

More importantly, if I create a user via the admin interface (http://
127.0.0.1:8000/admin/auth/user/add/) there's no apparent way to edit
any of the fields of my profile model.

Or if I create the user some other way, would I be able to pass
arguments to the User model to populate the profile?

Finally, how do I access the profile, is it like

  my_user_profile = User.objects.get(username="jim").get_profile() ?

Thanks for the help.

-Jim

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



auto authenticate

2010-03-25 Thread CrabbyPete
I am connecting facebook to an app I have running. In order not to
change a load of code I created a dummy account when someone logs in
through facebook. My only problem is I want to authenticate with this
account when they log  Is there a way to login in a user using the
encrypted password. I am using pyfacebook and FacebookUser is the
following model


class FacebookUser(models.Model):
user= models.ForeignKey(User, unique = True)
fb_uid  = models.CharField( max_length=100, blank = True,
unique = True)

def __unicode__(self):
if self.user.username == u'':
return str(self.pk)
return self.user.username


the fb_uid is the Facebook id I get back. Here is my view when I get
called from facebook

fb = request.facebook
 try:
  fid = FacebookUser.objects.get(Q(fb_uid = fb.uid))
except FacebookUser.DoesNotExist:
   return ...

name = fid.user
pswd = fid.user.password
user = auth.authenticate(username=name, password=pswd)
 if user is not None and user.is_active:
 auth.login(request, user)


pswd is an encrypted password. Is there a way for me to authenticate
with 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-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: How to locate the OS user name? [newbie]

2010-03-25 Thread BobAalsma
OK, found it - thanks!

Regards,
Bob

On Mar 25, 6:40 pm, "piz...@gmail.com"  wrote:
> Check the module index in the python website:http://docs.python.org/
> modindex.html
>
> There you will find everything about python modules like sys, os, and  
> others.
>
> Regards,
> Oscar C.
>
> El 25/03/2010, a las 18:28, BobAalsma escribió:
>
> > YES!
>
> > Works beautifully, thanks.
>
> > On the newbie part: how could I have found this?
> > I did find the os.environ and you've helped me discover how to look
> > inside, but what if I need something completely different?
>
> > Regards,
> > Bob

-- 
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: How to locate the OS user name? [newbie]

2010-03-25 Thread piz...@gmail.com
Check the module index in the python website: http://docs.python.org/ 
modindex.html


There you will find everything about python modules like sys, os, and  
others.


Regards,
Oscar C.

El 25/03/2010, a las 18:28, BobAalsma escribió:


YES!

Works beautifully, thanks.

On the newbie part: how could I have found this?
I did find the os.environ and you've helped me discover how to look
inside, but what if I need something completely different?

Regards,
Bob


--
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: block google indexer

2010-03-25 Thread creecode
Hello Vishnu,

You might find Django Robots < 
http://bitbucket.org/jezdez/django-robots/overview/
> of use.

On Mar 25, 6:18 am, "vishnu.kumar"  wrote:

> I need to block google indexer from indexing my site.
>
> If it was a static site, i would put a htaccess or robots.txt, but
> django is different right.
> I cant put robot meta tag also, cause there are many pages in my site.
>
> How do i do it then?

Toodle-loo.
creecode

-- 
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: How to locate the OS user name? [newbie]

2010-03-25 Thread BobAalsma
YES!

Works beautifully, thanks.

On the newbie part: how could I have found this?
I did find the os.environ and you've helped me discover how to look
inside, but what if I need something completely different?

Regards,
Bob

On Mar 25, 4:43 pm, Benjamin Reitzammer  wrote:
> Hi Bob,
> this not a Django specific question/problem but more a general Python 
> question.
> The information you are looking for is most likely located in the
> os.environ object.
> So take a look at  this in your python commandline/shell
>
> >>> import os
> >>> [i for i in os.environ.items()]
>
> and look for the item that contains the username you are looking for.
>
> HTH & Cheers
>
> Benjamin
>
> On Thu, Mar 25, 2010 at 16:27, BobAalsma  wrote:
> > I work as a single person on a single machine. I use an unstable
> > programme that requires me to employ more than one OS user. The
> > programme will store some files locally (in each specific user
> > environment).
>
> > I am trying to build a Django application to centralise the
> > information gathered by this unstable programme, but in some cases I
> > need to refer to the stored files. So I want to store the
> > "originating" OS user name in the database, along with the other
> > information.
>
> > So yes, there are concurrent users;  I know I will never use the same
> > user name twice; it is a single machine solution, not using any
> > network - I think there is no security problem to be solved here.
>
> > I have looked at the documentation and forums, but could not find an
> > answer to my question.
>
> > Regards,
> > Bob
>
> > --
> > 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: How to locate the OS user name? [newbie]

2010-03-25 Thread BobAalsma
Hi Benjamin,

Thanks, I'll have look.

Bob

On Mar 25, 4:43 pm, Benjamin Reitzammer  wrote:
> Hi Bob,
> this not a Django specific question/problem but more a general Python 
> question.
> The information you are looking for is most likely located in the
> os.environ object.
> So take a look at  this in your python commandline/shell
>
> >>> import os
> >>> [i for i in os.environ.items()]
>
> and look for the item that contains the username you are looking for.
>
> HTH & Cheers
>
> Benjamin
>
> On Thu, Mar 25, 2010 at 16:27, BobAalsma  wrote:
> > I work as a single person on a single machine. I use an unstable
> > programme that requires me to employ more than one OS user. The
> > programme will store some files locally (in each specific user
> > environment).
>
> > I am trying to build a Django application to centralise the
> > information gathered by this unstable programme, but in some cases I
> > need to refer to the stored files. So I want to store the
> > "originating" OS user name in the database, along with the other
> > information.
>
> > So yes, there are concurrent users;  I know I will never use the same
> > user name twice; it is a single machine solution, not using any
> > network - I think there is no security problem to be solved here.
>
> > I have looked at the documentation and forums, but could not find an
> > answer to my question.
>
> > Regards,
> > Bob
>
> > --
> > 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: what's wrong with this if statement structure

2010-03-25 Thread creecode
Hello Bobby,

On Mar 25, 9:42 am, Bobby Roberts  wrote:
> is there a quick way to do something like this in 1.1?

You could do the comparison at the view level and then set an
attribute on your object with the result.

Toodle-lo..
creecode

-- 
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: How to locate the OS user name? [newbie]

2010-03-25 Thread BobAalsma
I'd prefer not to as I keep switching between 15-20 users and find the
log in of the OS quite enough, thank you.
My beautiful but unstable programme makes it a good idea to
periodically fully log out and log in, say twice a day...

On Mar 25, 4:47 pm, Baurzhan Ismagulov  wrote:
> On Thu, Mar 25, 2010 at 08:27:37AM -0700, BobAalsma wrote:
> > I am trying to build a Django application to centralise the
> > information gathered by this unstable programme, but in some cases I
> > need to refer to the stored files. So I want to store the
> > "originating" OS user name in the database, along with the other
> > information.
>
> What about authenticating those users in your Django app?
>
> With kind regards,
> --
> Baurzhan Ismagulovhttp://www.kz-easy.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Problem logging into admin site

2010-03-25 Thread Tim


On Mar 25, 4:44 pm, Genghisu  wrote:
> Have you set SESSION_COOKIE_DOMAIN in settings.py?  Without that being
> set correctly, you'll run into the problem you've described above.  In
> your case,
>
> SESSION_COOKIE_DOMAIN = 'dev.mydomain.com'.
>
> http://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-domain

Hi Genghisu,

Yes I've tried that and it made no difference at all.

I've delved much deeper into the Django session code, in an attempt to
debug my problem. I added the following line of code to the
django.contrib.sessions.backends.base file:

def test_cookie_worked(self):
++ print "%s == %s" % (self.get(self.TEST_COOKIE_NAME),
self.TEST_COOKIE_VALUE)
return self.get(self.TEST_COOKIE_NAME) ==
self.TEST_COOKIE_VALUE

That outputs the following when I attempt to log in:


[25/Mar/2010 16:55:09] "GET /admin/ HTTP/1.1" 200 1680
None == worked
[25/Mar/2010 16:55:14] "POST /admin/ HTTP/1.1" 200 1826

-- 
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: Multiple querysets for dictionary

2010-03-25 Thread Daniel Roseman
On Mar 25, 4:27 pm, grimmus  wrote:
> Hi,
>
> For my xml sitemap i would like to show blog posts and pages from the
> CMS. How can i pass 2 querysets to the dictionary ?
>
> What i have so far is below, it's obviously wrong :-(
>
> info_dict = {
>     'queryset': Page.objects.filter(active=1),
>     'queryset': Entry.objects.filter(status=1),
>     'date_field': 'pub_date',
>
> }
>
> Thanks for any help

What are you expecting this to output? The way sitemaps work is to
have a class for each type of page you want to index, but there's a
shortcut for generic views using the GenericSitemap class and an info
dict. However, again that class only refers to a single type of page.
If you've got different generic views using different models, you can
simply use a separate dictionary - there's nothing magical about the
'info_dict' name, you can have different dictionaries for different
models.
--
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-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: How to locate the OS user name? [newbie]

2010-03-25 Thread Benjamin Reitzammer
Hi Bob,
this not a Django specific question/problem but more a general Python question.
The information you are looking for is most likely located in the
os.environ object.
So take a look at  this in your python commandline/shell

>>> import os
>>> [i for i in os.environ.items()]

and look for the item that contains the username you are looking for.


HTH & Cheers

Benjamin



On Thu, Mar 25, 2010 at 16:27, BobAalsma  wrote:
> I work as a single person on a single machine. I use an unstable
> programme that requires me to employ more than one OS user. The
> programme will store some files locally (in each specific user
> environment).
>
> I am trying to build a Django application to centralise the
> information gathered by this unstable programme, but in some cases I
> need to refer to the stored files. So I want to store the
> "originating" OS user name in the database, along with the other
> information.
>
> So yes, there are concurrent users;  I know I will never use the same
> user name twice; it is a single machine solution, not using any
> network - I think there is no security problem to be solved here.
>
> I have looked at the documentation and forums, but could not find an
> answer to my question.
>
> Regards,
> Bob
>
> --
> 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.
>
>

-- 
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: Problem logging into admin site

2010-03-25 Thread Genghisu
Have you set SESSION_COOKIE_DOMAIN in settings.py?  Without that being
set correctly, you'll run into the problem you've described above.  In
your case,

SESSION_COOKIE_DOMAIN = 'dev.mydomain.com'.

http://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-domain

On Mar 25, 7:47 am, Tim  wrote:
> Hi,
>
> I've just set up the admin site and when I try to log in, I get the
> following message:
>
> "Looks like your browser isn't configured to accept cookies. Please
> enable cookies, reload this page, and try again."
>
> Following extensive searching through this group, google, and just
> about every other resource I can think of, there seem to be a lot of
> references to a common bug in regard to servers running PHP and Python
> through mod_python. This is not the case for me.
>
> I'm currently running Ubuntu Jaunty, with Python 2.6 and Django 1.1.1.
> The web server is Nginx, forwarding Python to Apache using modwsgi.
> However, when I attempted to access the admin site, I was connecting
> through the Django dev server, not the web sever:
>
> ./manage.py runserver 0.0.0.0:8000
>
> Accessing using the following address in my browser (both Chrome and
> FF):
>
> http://dev.mydomain.com:8000/admin/
>
> I'm afraid I'm at a complete loss; can anyone help?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: what's wrong with this if statement structure

2010-03-25 Thread Tom Evans
On Thu, Mar 25, 2010 at 4:42 PM, Bobby Roberts  wrote:
> thanks for your quick reply... is there a quick way to do something
> like this in 1.1?
>

Import the smart_if as a standalone, separate tag:

http://www.djangosnippets.org/snippets/1350/

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: what's wrong with this if statement structure

2010-03-25 Thread Bobby Roberts
thanks for your quick reply... is there a quick way to do something
like this in 1.1?




On Mar 25, 12:40 pm, Karen Tracey  wrote:
> On Thu, Mar 25, 2010 at 12:28 PM, Bobby Roberts  wrote:
> > sorry -
>
> > it is in the template an the traceback thrown is:
>
> > 'if' statement improperly formatted
>
> You are trying to use a feature added for 1.2 (smart if) with 1.1.X level
> code.
>
> 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-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: what's wrong with this if statement structure

2010-03-25 Thread Karen Tracey
On Thu, Mar 25, 2010 at 12:28 PM, Bobby Roberts  wrote:

> sorry -
>
> it is in the template an the traceback thrown is:
>
> 'if' statement improperly formatted
>

You are trying to use a feature added for 1.2 (smart if) with 1.1.X level
code.

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-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: what's wrong with this if statement structure

2010-03-25 Thread James Bennett
On Thu, Mar 25, 2010 at 11:28 AM, Bobby Roberts  wrote:
> it is in the template an the traceback thrown is:
>
> 'if' statement improperly formatted

The documentation states:

> New in Django Development version.
> if tags may also use the operators ==, !=, <, >, <=, >= and in which work as 
> follows:

In other words, this is something which is not yet part of a released
version of Django. You are almost certainly using Django 1.1 or older,
where these operators were not supported.

In the future:

1. Take care to stick to the documentation for the version of Django
you're using.

2. Keep an eye out for notes about when particular features were
added; they'll appear in the documentation, in bold text, just before
the description of the feature.



-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of 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-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: problems with get_or_create

2010-03-25 Thread Tom Evans
On Thu, Mar 25, 2010 at 4:23 PM, Malcolm Tredinnick
 wrote:
> No, he's not, because Kenneth said that the instance exists. In your

Actually, he described both situations where the instance exists, but
with different values for the non-key attributes of the model, and
where the instance doesn't exist.
pedant++

> example, the instance doesn't exist and thus a new object is attempted
> to be created. The restrictions at that point are the same as when
> creating a new object from scratch, as noted in my reply. The caller of
> get_or_create() will always know what the various constraints are on the
> model and must allow for that in their code.
>
> Regards,
> Malcolm
>
>

Well, quite. His problem was that he wasn't allowing for the
constraints in his code because he was unaware of the 'defaults' kwarg
to get_or_create(). With that addition, his problems when an instance
with the same unique key exists, and when no instance exists are both
fixed.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: what's wrong with this if statement structure

2010-03-25 Thread Bobby Roberts
sorry -

it is in the template an the traceback thrown is:

'if' statement improperly formatted



On Mar 25, 12:11 pm, Tom Evans  wrote:
> On Thu, Mar 25, 2010 at 4:09 PM, Bobby Roberts  wrote:
> > 92     {%ifequal au.ReservePrice 0%}
> > 93           None
> > 94     {%else%}
> > 95           {%if au.ReservePrice > au.currentbid %}Met{%else%}Not
> > Met{%endif%}
> > 96      {%endifequal%}
>
> Since you haven't said what goes wrong with it, I will have to guess
> that it is valid template code (looks it) but it just doesn't behave
> as you expect. In that case, I'd imagine that somewhere you are
> comparing a string to an int, probably in the ifequal.
>
> Cheers
>
> Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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.



Multiple querysets for dictionary

2010-03-25 Thread grimmus
Hi,

For my xml sitemap i would like to show blog posts and pages from the
CMS. How can i pass 2 querysets to the dictionary ?

What i have so far is below, it's obviously wrong :-(

info_dict = {
'queryset': Page.objects.filter(active=1),
'queryset': Entry.objects.filter(status=1),
'date_field': 'pub_date',
}

Thanks for any help

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: problems with get_or_create

2010-03-25 Thread Malcolm Tredinnick
On Thu, 2010-03-25 at 15:58 +, Tom Evans wrote:
[...]
> 
> He is describing this situation:
> 
> >>> User.objects.get(username='tevans...@googlemail.com')
> 
> >>> User.objects.get_or_create(username='tevans...@googlemail.com')
> (, False)
> >>> User.objects.get(username='tevans...@googlemail.com').first_name
> u'Tom'
> >>> User.objects.get(username='tevans...@googlemail.com', first_name='Thomas')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "site-packages/django/db/models/manager.py", line 119, in get
> return self.get_query_set().get(*args, **kwargs)
>   File "django/db/models/query.py", line 305, in get
> % self.model._meta.object_name)
> DoesNotExist: User matching query does not exist.
> >>> User.objects.get_or_create(username='tevans...@googlemail.com', 
> >>> first_name='Thomas')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "site-packages/django/db/models/manager.py", line 122, in
> get_or_create
> return self.get_query_set().get_or_create(**kwargs)
>   File "site-packages/django/db/models/query.py", line 343, in 
> get_or_create
> raise e
> IntegrityError: (1062, "Duplicate entry '' for key 2")

No, he's not, because Kenneth said that the instance exists. In your
example, the instance doesn't exist and thus a new object is attempted
to be created. The restrictions at that point are the same as when
creating a new object from scratch, as noted in my reply. The caller of
get_or_create() will always know what the various constraints are on the
model and must allow for that in their code.

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-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: Is it possible to change the width of the boxes displayed by the filter_horizontal in Django admin interface?

2010-03-25 Thread rc
Walt,

Thanks for the response. This is making me crazy. Seems like this
should be an easy thing to do.

I have tried your suggestion, but I am not totally clear on where in
the admin.py It is just not loading up the new media class.

Am I supposed to add the resize class as a separate class like this:
#
class ResizeFilterAdmin(admin.ModelAdmin):
class Media:
css = {
'all':('bisite.css',)
}

class ProfileAdmin(admin.ModelAdmin):
search_fields = ('profile_name',)
ordering = ('profile_name',)
filter_horizontal = ('profile_test',)
#...

or add it into the admin that uses the filter_horizontal like this:

class ProfileAdmin(admin.ModelAdmin):
search_fields = ('profile_name',)
ordering = ('profile_name',)
filter_horizontal = ('profile_test',)

   class ResizeFilterAdmin(admin.ModelAdmin):
class Media:
css = {
'all':('bisite.css',)
}

Also, the relative path to the css file? What is that relative to? My
admin media so it goes in the same directory as the other admin css
files, or relative to my application directory.

I appologize for the basic questions. I am just having a hard time
grasping the admin modification stuff.




On Mar 23, 9:22 am, Walt  wrote:
> You'll need add a stylesheet Media class to your admin class:
>
> class ResizeFilterAdmin(admin.ModelAdmin):
>     # 
>
>     class Media:
>         css = { 'all': ('/relative/path/to/supplemental.css'), }
>
> Then, in that CSS file you'll need to specify the width of your
> element:
>
> /* by class */
> .filtered {
>     width: 350px;
>
> }
>
> /* or by object id */
> #id_yourfieldname_from {
>     width: 350px;
>
> }
>
> #id_yourfieldname_to {
>     width: 350px;
>
> }
>
> This should work. :-)
>
> Walt

-- 
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: what's wrong with this if statement structure

2010-03-25 Thread Tom Evans
On Thu, Mar 25, 2010 at 4:09 PM, Bobby Roberts  wrote:
> 92     {%ifequal au.ReservePrice 0%}
> 93           None
> 94      {%else%}
> 95           {%if au.ReservePrice > au.currentbid %}Met{%else%}Not
> Met{%endif%}
> 96      {%endifequal%}
>

Since you haven't said what goes wrong with it, I will have to guess
that it is valid template code (looks it) but it just doesn't behave
as you expect. In that case, I'd imagine that somewhere you are
comparing a string to an int, probably in the ifequal.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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.



what's wrong with this if statement structure

2010-03-25 Thread Bobby Roberts
92 {%ifequal au.ReservePrice 0%}
93   None
94  {%else%}
95   {%if au.ReservePrice > au.currentbid %}Met{%else%}Not
Met{%endif%}
96  {%endifequal%}

-- 
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: problems with get_or_create

2010-03-25 Thread Tom Evans
On Thu, Mar 25, 2010 at 3:47 PM, Malcolm Tredinnick
 wrote:
> On Thu, 2010-03-25 at 11:22 +0530, Kenneth Gonsalves wrote:
>> hi,
>>
>> I have a model like this:
>>
>> name - unique
>> slno - not null
>> mode - not null
>>
>> If the instance does not exist and I give all three values to get_or_create,
>> it works
>>
>> if the instance exists, and I give values for slno and mode which are 
>> different
>> from the existing ones - I get a programming error as get_or_create tries to
>> create a new instance and falls foul of the unique constraint on name. It
>> works if I only give the value for name - it gets the instance and then I can
>> add the new values and save
>
> I don't understand what you are saying here. If the instance exists (as
> in, the filter parameters passed to get would return a single item),
> that instance is returned and the default parameters are never
> considered. So the values you pass for slno and mode are irrelevant. If
> the equivalent get() call would not return anything, then the instance
> does not exist and it's clear that the default parameter must contain
> correct data that can be used to create a new object -- including not
> violating any unique constraints. Perhaps you could show the code call
> you are making, rather than writing it out as a sentence.
>
> In short: get_or_create() first runs the get(). If that returns
> something, it is what is returned. If the get() fails with no object
> being present, then the instance DOES NOT exist and a new one is
> created, with all the same requirements as if you'd created a new object
> from scratch (e.g. no unique constraint violations).
>
> Malcolm
>
>

He is describing this situation:

>>> User.objects.get(username='tevans...@googlemail.com')

>>> User.objects.get_or_create(username='tevans...@googlemail.com')
(, False)
>>> User.objects.get(username='tevans...@googlemail.com').first_name
u'Tom'
>>> User.objects.get(username='tevans...@googlemail.com', first_name='Thomas')
Traceback (most recent call last):
  File "", line 1, in 
  File "site-packages/django/db/models/manager.py", line 119, in get
return self.get_query_set().get(*args, **kwargs)
  File "django/db/models/query.py", line 305, in get
% self.model._meta.object_name)
DoesNotExist: User matching query does not exist.
>>> User.objects.get_or_create(username='tevans...@googlemail.com', 
>>> first_name='Thomas')
Traceback (most recent call last):
  File "", line 1, in 
  File "site-packages/django/db/models/manager.py", line 122, in
get_or_create
return self.get_query_set().get_or_create(**kwargs)
  File "site-packages/django/db/models/query.py", line 343, in get_or_create
raise e
IntegrityError: (1062, "Duplicate entry '' for key 2")

IE, where Model.objects.get(**kwargs) does not return an object, but
Model.objects.create(**kwargs) would fail, which is fixed by knowing
about the 'defaults' kwarg to get_or_create:

>>> User.objects.get_or_create(username='tevans...@googlemail.com',
... defaults={'first_name': 'Thomas', })
(, False)

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: problems with get_or_create

2010-03-25 Thread Malcolm Tredinnick
On Thu, 2010-03-25 at 11:22 +0530, Kenneth Gonsalves wrote:
> hi,
> 
> I have a model like this:
> 
> name - unique
> slno - not null
> mode - not null
> 
> If the instance does not exist and I give all three values to get_or_create, 
> it works
> 
> if the instance exists, and I give values for slno and mode which are 
> different 
> from the existing ones - I get a programming error as get_or_create tries to 
> create a new instance and falls foul of the unique constraint on name. It 
> works if I only give the value for name - it gets the instance and then I can 
> add the new values and save

I don't understand what you are saying here. If the instance exists (as
in, the filter parameters passed to get would return a single item),
that instance is returned and the default parameters are never
considered. So the values you pass for slno and mode are irrelevant. If
the equivalent get() call would not return anything, then the instance
does not exist and it's clear that the default parameter must contain
correct data that can be used to create a new object -- including not
violating any unique constraints. Perhaps you could show the code call
you are making, rather than writing it out as a sentence.

In short: get_or_create() first runs the get(). If that returns
something, it is what is returned. If the get() fails with no object
being present, then the instance DOES NOT exist and a new one is
created, with all the same requirements as if you'd created a new object
from scratch (e.g. no unique constraint violations).

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-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: How to locate the OS user name? [newbie]

2010-03-25 Thread Baurzhan Ismagulov
On Thu, Mar 25, 2010 at 08:27:37AM -0700, BobAalsma wrote:
> I am trying to build a Django application to centralise the
> information gathered by this unstable programme, but in some cases I
> need to refer to the stored files. So I want to store the
> "originating" OS user name in the database, along with the other
> information.

What about authenticating those users in your Django app?

With kind regards,
-- 
Baurzhan Ismagulov
http://www.kz-easy.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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.



How to locate the OS user name? [newbie]

2010-03-25 Thread BobAalsma
I work as a single person on a single machine. I use an unstable
programme that requires me to employ more than one OS user. The
programme will store some files locally (in each specific user
environment).

I am trying to build a Django application to centralise the
information gathered by this unstable programme, but in some cases I
need to refer to the stored files. So I want to store the
"originating" OS user name in the database, along with the other
information.

So yes, there are concurrent users;  I know I will never use the same
user name twice; it is a single machine solution, not using any
network - I think there is no security problem to be solved here.

I have looked at the documentation and forums, but could not find an
answer to my question.

Regards,
Bob

-- 
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: basic django auth fails on valid user

2010-03-25 Thread Tom Evans
On Thu, Mar 25, 2010 at 2:48 PM, Jim N  wrote:
> Thanks Tim,
>
> Yes, I just saw this.  I was subclassing auth.User because I didn't
> know the right way to do it.
>
> Now I am on the right track.
>
> Just one thing I can't figure out.
>
> "When a user profile model has been defined and specified in this
> manner, each User object will have a method -- get_profile() -- which
> returns the instance of the user profile model associated with that
> User. [¶] The method get_profile() does not create the profile, if it
> does not exist."
>
> So the profile is the model that I've created to hold the extra stuff
> about my user, and it's not automatically created.  I can't quite
> picture where or how it would get created.  I have a couple of ways to
> create a user - through my app when someone takes some actions, or
> through the django admin.
>
> If anyone cares to expound, or share some sample code, that would be
> great.
>
> Thanks,
> Jim

See my response to
http://groups.google.com/group/django-users/browse_thread/thread/2af584b66b8a38a3/cad58c52a3990830?show_docid=cad58c52a3990830

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: basic django auth fails on valid user

2010-03-25 Thread Jim N
Thanks Tim,

Yes, I just saw this.  I was subclassing auth.User because I didn't
know the right way to do it.

Now I am on the right track.

Just one thing I can't figure out.

"When a user profile model has been defined and specified in this
manner, each User object will have a method -- get_profile() -- which
returns the instance of the user profile model associated with that
User. [¶] The method get_profile() does not create the profile, if it
does not exist."

So the profile is the model that I've created to hold the extra stuff
about my user, and it's not automatically created.  I can't quite
picture where or how it would get created.  I have a couple of ways to
create a user - through my app when someone takes some actions, or
through the django admin.

If anyone cares to expound, or share some sample code, that would be
great.

Thanks,
Jim



On Mar 24, 7:47 pm, Tim Shaffer  wrote:
> I think this could all be simplified a bit if you used a UserProfile
> model instead of subclassing auth.User.
>
> http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-...
>
> Was there a specific reason you were subclassing auth.User?

-- 
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: Altering the auth_user model?

2010-03-25 Thread Bjunix
I would not recommend to mess with contrib.auth.models. If you want to
make some fields of the User model required I would do this on form
level. Just create a custom model form for User and override the
fields in questions.

On Mar 25, 2:43 pm, derek  wrote:
> On Mar 24, 11:21 pm, Thierry Chich  wrote:
>
>
>
> > Le mercredi 24 mars 2010 16:53:12, Sandman a écrit :
>
> > > Hi Derek,
>
> > > One way to do this would be to create a proxy model that can be used
> > > throughout your project.
>
> > > Check out
> > >http://docs.djangoproject.com/en/dev/topics/db/models/#proxy-modelsfor
> > > more info.
>
> > Hi,
>
> > This is what is said in one page, but in an other, it is suggested that you
> > just create your class with yours fields and put  foreignkey on User.
>
> > It work very well, indeed.
>
> >http://docs.djangoproject.com/en/1.1/topics/auth/#topics-auth
> > see "Storing additional information about users"¶
>
> > > Take care,
> > > Rajiv.
>
> > > On 3/24/10 7:44 AM, Derek wrote:
> > > > I am currently using UserProfile to create additional fields that are
> > > > needed for my users.
>
> > > > I would like to be able to alter the existing User model to use the same
> > > > fields, but make some of them "required" (show up as bold on the form)
> > > > e,g, the first name and last name. How would I do that?
>
> > > > Thanks
> > > > Derek
>
> Thierry
>
> Thanks, but I already am using the UserProfile for *additional* fields
> - I need to be able to change the behaviour of the *existing* fields
> in the auth_user (aka User).
>
> Derek

-- 
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: Simple export of CSV

2010-03-25 Thread Alex Robbins
Not sure if this will help, but the docs have a pretty in-depth
explanation of doing csv export. 
http://docs.djangoproject.com/en/dev/howto/outputting-csv/

HTH,
Alex

On Mar 24, 3:03 pm, jlwlynn  wrote:
> I'm trying to simply export CSV, but have failed miserably.  First I
> perform a search and the query set is displayed in a template.  I want
> to have an export button that will export the data on the page, but
> unfortunately, I lost the query set and even if I were to have it as a
> parameter, it would only see it as a string to my exportCSV function.
> Any ideas?  THANKS IN ADVANCE
>
> jason

-- 
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: Altering the auth_user model?

2010-03-25 Thread derek
On Mar 24, 11:21 pm, Thierry Chich  wrote:
> Le mercredi 24 mars 2010 16:53:12, Sandman a écrit :
>
> > Hi Derek,
>
> > One way to do this would be to create a proxy model that can be used
> > throughout your project.
>
> > Check out
> >http://docs.djangoproject.com/en/dev/topics/db/models/#proxy-modelsfor
> > more info.
>
> Hi,
>
> This is what is said in one page, but in an other, it is suggested that you
> just create your class with yours fields and put  foreignkey on User.
>
> It work very well, indeed.
>
> http://docs.djangoproject.com/en/1.1/topics/auth/#topics-auth
> see "Storing additional information about users"¶
>
>
>
> > Take care,
> > Rajiv.
>
> > On 3/24/10 7:44 AM, Derek wrote:
> > > I am currently using UserProfile to create additional fields that are
> > > needed for my users.
>
> > > I would like to be able to alter the existing User model to use the same
> > > fields, but make some of them "required" (show up as bold on the form)
> > > e,g, the first name and last name. How would I do that?
>
> > > Thanks
> > > Derek
>

Thierry

Thanks, but I already am using the UserProfile for *additional* fields
- I need to be able to change the behaviour of the *existing* fields
in the auth_user (aka User).

Derek

-- 
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: Customized filter for Django Admin

2010-03-25 Thread derek
On Mar 24, 5:30 pm, adam  wrote:
> derek
>
> i want to do the same thing.
>
> first, the site below mentioned about 
> filtering.http://patrickbeeson.com/blog/2008/aug/11/how-create-user-specific-ad...
>
> in this time, you have to give country_id as a request parameter by
> changing link url.
> link url is like this: .../region?country_id=1
>
> and admin class is like this:
>
> class RegionAdmin(admin.Modeladmin):
>     ...
>     def queryset(self, request):
>         qs = super(ReqionAdmin, self).queryset(request)
>         if request.GET.get('country_id'):

Unfortunately, when I try this, my application call to display the
list of regions i.e.
/admin/edit/region/
gets redirected to
/admin/edit/region/?e=1
and that gives me a message in the browser display:
"Something's wrong with your database installation. Make sure the
appropriate database tables have been created, and make sure the
database is readable by the appropriate user."

I'm not sure where this "?e=1" comes from?  Maybe something else is
need to be set first?

Thanks
Derek

-- 
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: block google indexer

2010-03-25 Thread Masklinn
On 25 Mar 2010, at 14:18 , vishnu.kumar wrote:
> 
> Hi,
> 
> I need to block google indexer from indexing my site.
> 
> If it was a static site, i would put a htaccess or robots.txt, but
> django is different right.
> I cant put robot meta tag also, cause there are many pages in my site.
> 
> How do i do it then?
> 
> Vishnu Kumar

1. Match the "/robots.txt" address to return the correct content to
block robots, either statically (intercept the URL using apache) or
dynamically (specify that URL in Django's urlconf)
2. If you're using a "base" template of which all pages in the site
inherit (which you should), you can put the correct meta tag in all
pages
3. I'm pretty sure Google's Webmaster Tools allow you to control
the behavior of the robots on your page, though that's google-specific
(won't work for Yahoo's and Bing's bots)

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



block google indexer

2010-03-25 Thread vishnu.kumar
Hi,

I need to block google indexer from indexing my site.

If it was a static site, i would put a htaccess or robots.txt, but
django is different right.
I cant put robot meta tag also, cause there are many pages in my site.

How do i do it then?

Vishnu Kumar

-- 
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: Django with a tiny linux distribution

2010-03-25 Thread Richard Shebora
look at turnkeylinux.com

They have an ubuntu django base system ready to go.

Thanks,
Richard

On Thu, Mar 25, 2010 at 8:11 AM, Pythoni  wrote:
> Has anybody tried using Django with a tiny linux distribution?
> Thanks for replies
> Mm.
>
> --
> 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.
>
>

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



Problem logging into admin site

2010-03-25 Thread Tim
Hi,

I've just set up the admin site and when I try to log in, I get the
following message:

"Looks like your browser isn't configured to accept cookies. Please
enable cookies, reload this page, and try again."

Following extensive searching through this group, google, and just
about every other resource I can think of, there seem to be a lot of
references to a common bug in regard to servers running PHP and Python
through mod_python. This is not the case for me.

I'm currently running Ubuntu Jaunty, with Python 2.6 and Django 1.1.1.
The web server is Nginx, forwarding Python to Apache using modwsgi.
However, when I attempted to access the admin site, I was connecting
through the Django dev server, not the web sever:

./manage.py runserver 0.0.0.0:8000

Accessing using the following address in my browser (both Chrome and
FF):

http://dev.mydomain.com:8000/admin/

I'm afraid I'm at a complete loss; can anyone help?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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.



Django + Raw SQL: not returning a M2M key set of related values properly.

2010-03-25 Thread Sam Walters
http://pastebin.com/dFW6MdBm

Hi
I have a raw MySQL query which im using for performance reasons.
It works great except under one condition. When i want to apply  a
filter based on a directories related table 'tags'. In SQL i use this:
`directory_directorytag`.`name` = '%s'

now typically i would want to see if the directory is associated with
the tag im after. And then get the entire set of tags including the
match.
It follows my models such that its a basic many-to-many relationship.

eg django orm:
for a in Directory.objects.filter(directorytag__name__exact=''):
v = a.directorytag_set.all().values('name')

the directory may have a set of tags 'tags'Apple, Pear, Nectarine etc.

However my SQL query only returns the exact match 'Apple' and none of
the other tags in the set.

Yes i normally end up with a nice list of dictionaries, there are
duplicates the results for the other keys eg:
[{... 'keya':'valuea', 'tag':'apple' ...},{... 'keya':'valuea',
'tag':'pear' ...}]
which i transform to:
[{... 'keya':'valuea', 'tag':['apple','pear'] ...}]
That is not an issue. The issue is in the WHERE clause as soon as i
search for a tag it literally only returns the results with just that
tag not the entire group.

I was searching all evening and was not able to see an easy way to fix this.
Attempted to use outer/right joins however i dont know enough about
MySQL in particular to work it out.

Any help would probably save me most of tomorrow ;) I have to get it
solved some time. And raw sql seems to be the best as far as
performance and minimising hits on db.

cheers

sam

-- 
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: Django with a tiny linux distribution

2010-03-25 Thread Baurzhan Ismagulov
On Thu, Mar 25, 2010 at 05:11:28AM -0700, Pythoni wrote:
> Has anybody tried using Django with a tiny linux distribution?

It depends on how you define "tiny". I've just bootstrapped Debian,
installed Django and apache2, and removed docs. The result is:

Base system154 MB
Django  52 MB
apache2 50 MB

This takes into account all dependencies of Debian packages (e.g.,
apache2 requires perl, etc.). Given that there are 32-MB base systems,
I'd expect a system with Django to fit a 64 to 128-MB compressed
filesystem (this will also depend on your requirements -- python libs,
DBMS, etc.), but I haven't tried that.

With kind regards,
-- 
Baurzhan Ismagulov
http://www.kz-easy.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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.



Django with a tiny linux distribution

2010-03-25 Thread Pythoni
Has anybody tried using Django with a tiny linux distribution?
Thanks for replies
Mm.

-- 
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: problems with get_or_create

2010-03-25 Thread Tom Evans
On Thu, Mar 25, 2010 at 10:29 AM, Daniel Roseman  wrote:
>
> Actually the kwarg is 'defaults', not 'initial'.
>
> See 
> http://docs.djangoproject.com/en/1.1/ref/models/querysets/#get-or-create-kwargs
> --
> DR.
>

Indeed :/

coffee++

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: problems with get_or_create

2010-03-25 Thread Daniel Roseman
On Mar 25, 9:32 am, Tom Evans  wrote:
> On Thu, Mar 25, 2010 at 5:52 AM, Kenneth Gonsalves  wrote:
> > hi,
>
> > I have a model like this:
>
> > name - unique
> > slno - not null
> > mode - not null
>
> > If the instance does not exist and I give all three values to get_or_create,
> > it works
>
> > if the instance exists, and I give values for slno and mode which are 
> > different
> > from the existing ones - I get a programming error as get_or_create tries to
> > create a new instance and falls foul of the unique constraint on name. It
> > works if I only give the value for name - it gets the instance and then I 
> > can
> > add the new values and save
>
> > if the instance does not exist and I only give the value for name, I get a
> > programming error that the not null constraints on slno and mode are 
> > violated.
>
> > so it looks to me that get_or_create will only work reliably when there are 
> > no
> > not null or unique constraints in the model. Or am I missing something?
>
> I think you are missing the optional kwarg 'initial', which is a
> dictionary of initial values to use when the instance does not exist.
> So not
>
> foo, created = Foo.objects.get_or_create(name=name,
>                                          sino=sino,mode=mode)
>
> but
>
> foo, created = Foo.objects.get_or_create(name=name,
>                                 initial={'sino': sino, 'mode': mode, })
>
> Cheers
>
> Tom

Actually the kwarg is 'defaults', not 'initial'.

See 
http://docs.djangoproject.com/en/1.1/ref/models/querysets/#get-or-create-kwargs
--
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-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: Simple export of CSV

2010-03-25 Thread Tom Evans
On Wed, Mar 24, 2010 at 8:16 PM, Shawn Milochik  wrote:
> Have your 'export' button make an AJAX call to a view, which creates the CSV 
> file and prompts the user to 'Save As.'
>
> Details:
>
>        1. Use the same view you currently have, with an 'if' statement which 
> returns a standard (html) response or a CSV file based on a slug in your URL.
>
>        2.  You're going to have to re-submit the parameters in your AJAX 
> call. I recommend just using jQuery's serialize() and .post() to do this with 
> no sweat.
>
>        3. An HTTP response is a file-like object. Save your CSV to it. You'll 
> also need to change the contenttype. Great example here: 
> http://docs.djangoproject.com/en/1.1/howto/outputting-csv/
>
> End result: Someone runs your report. They see the results. They click the 
> 'Export CSV button/link/graphic,' and they're prompted by their browser to 
> save a CSV file without leaving the page they're on.
>
> I'm doing almost exactly this, with the exception that I'm providing an Excel 
> spreadsheet (xlwt module instead of csv and a different contenttype).
>
> Shawn
>

Browsers generally don't display CSV inline, they will prompt to
download, so there is no need for AJAX nonsense. Just create a link to
a download view with the appropriate arguments in your initial result
page. When the user clicks the link, their browser will prompt them to
download the file, and the browser will remain on the results page.

The download view can be the same as the results view, with an
additional argument to denote that it should return CSV.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: problems with get_or_create

2010-03-25 Thread Tom Evans
On Thu, Mar 25, 2010 at 5:52 AM, Kenneth Gonsalves  wrote:
> hi,
>
> I have a model like this:
>
> name - unique
> slno - not null
> mode - not null
>
> If the instance does not exist and I give all three values to get_or_create,
> it works
>
> if the instance exists, and I give values for slno and mode which are 
> different
> from the existing ones - I get a programming error as get_or_create tries to
> create a new instance and falls foul of the unique constraint on name. It
> works if I only give the value for name - it gets the instance and then I can
> add the new values and save
>
> if the instance does not exist and I only give the value for name, I get a
> programming error that the not null constraints on slno and mode are violated.
>
> so it looks to me that get_or_create will only work reliably when there are no
> not null or unique constraints in the model. Or am I missing something?

I think you are missing the optional kwarg 'initial', which is a
dictionary of initial values to use when the instance does not exist.
So not

foo, created = Foo.objects.get_or_create(name=name,
 sino=sino,mode=mode)

but

foo, created = Foo.objects.get_or_create(name=name,
initial={'sino': sino, 'mode': mode, })

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Overriding admin Media class

2010-03-25 Thread Sam Lai
On 25 March 2010 09:25, Scot Hacker  wrote:
>
> 
> It sounds like you're saying that the model method is not
> attaching to an instance like it usually does (which is why "self"
> doesn't work). But I'm no closer to figuring out how why it's
> different from model methods accessed from within views, or how I can
> fix it.

It's different because the Media class is a class itself, even though
its definition is nested within the model/form class. It only has
access to the methods/properties/variables it contains (unless it is
given something else when constructed).

The solution to your problem is here -
http://docs.djangoproject.com/en/dev/topics/forms/media/#media-as-a-dynamic-property

Admin media is based on Forms media, so the same principles apply.

Sidenote - what's you've implemented is documented at the top of that
link, and as stated, it is designed for static media. follow the
'media as a dynamic property' section and you should be able to
achieve what you want.

Here's an example from my CkWidget class (no if blocks at the moment,
but you can easily add them there as it is just a normal instance
method inside your class):

def _media(self):
# add CKEditor JS to page. It is assumed that it is located at
# MEDIA_URL + 'js/ckeditor/ckeditor.js' unless base path is overridden
# in settings
js = [settings.CKEDITOR_BASEPATH + 'ckeditor.js']

return widgets.Media(js=js)

media = property(_media)

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