Re: Current user in model.save() context

2009-07-21 Thread Bartłomiej Górny

Matthias Kestenholz wrote:
> On Mon, Jul 20, 2009 at 9:26 AM, Bartłomiej Górny wrote:
>> [...]
>>> there is a cookbook recipe for achieving this sort of thing:
>>>
>>> http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
>> Yep, that's exactly what I did :)
>>
>>> That's deep in the category of 'give them rope to hang themselves
>>> with' though. You should understand the implications and design
>>> decisions involved before hacking your way around it.
>> I give +1 to Joshua's request - plz explain.
>>
> 
> thread locals have all the problems which are generally associated
> with global variables. They might be overwritten by other code, they
> make testing extremely difficult because the behavior of methods may
> depend on non-obvious circumstances and it's not clear from the method
> signatures which variables are really used -- in short, it makes code
> maintenance much harder than it needs to be.
> 

Thanks for explaining that - I see your point, and I generally agree, 
though I'd like to comment on a couple of things:

> I'll try giving a few examples:
> 
> - You have a field on your model called last_modified_by, and you
> automatically assign request.user in the save() method. You made this
> piece of code much harder to test in an unittest than it needs to be,
> because now you have to provide the complete environment including the
> variables from the threadlocals space in your testsuite. More code is
> needed, and the probability that the code and the testsuite (and
> eventual documentation) get out of sync gets bigger and bigger.

Actually, not necessarily - in testing environment you can simply 
replace the function that gives you current user. Though I understand 
that some people may find it disgusting.

> - Something which I've done for a CRM system which we've developped
> for internal use together with another company was giving Tasks access
> levels, so that we were able to make certain tasks viewable only by
> the management. I built a manager which uses the user information from
> thread local space to filter the queryset automatically according to
> the profile of the currently authenticated user. With this seemingly
> simple move I've made it impossible to use loaddata/dumpdata, because
> no user exists, and I made it very non-obvious that the list of
> viewable tasks depends on the user. You would not get the idea that
> filtering is going on in the templates or even in a big part of the
> code. This is not a big problem when developping alone, but it can
> really hamper progress if someone else takes over the codebase.
> 

True. For getting/filtering, user should be passed explicitly.

> In short: It's easy and it gets the job done, but will come back and
> bite you later for sure. Don't give in to the temptation -- it's much
> better to write custom template tags where you can pass the user
> explicitly to the function, which makes it very clear that the
> output/the result of a certain function depends on the user. It also
> makes testing a breeze, because the behavior of methods is only
> determined by their arguments (as it should be), not by other
> circumstances or the current weather.

There are two sides to that - for view functions, you can write 
templatetags. But you have also to create and save objects, and then you 
have to set or pass the user manually every time you create or save 
anything anywhere in your code. This means more typing, and it is also 
easy to forget about it, so you get another kind of trouble. As far as 
I'm concerned, the main use of this way of getting user is creating 
objects, not filtering.

Bartek

> 



> 
> Matthias
> 
> > 


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



Re: Windows development server problem

2009-07-21 Thread Sam Lai

Did you forget any imports?

Maybe your code snippet's identifiers clashed with the default django ones?

Are there any errors in stdout?

2009/7/21 cwurld :
>
> Hi,
>
> I have a snippet of code that runs fine as a standalone program. But
> when I incorporate it into a view and access that view w the
> development server, the snippet no longer works.
>
> What is the difference between the python interpreter and the
> development server?
>
> Thanks,
> Chuck
>
> >
>

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



Re: Current user in model.save() context

2009-07-21 Thread Bartłomiej Górny

Joshua Russo wrote:
> On Mon, Jul 20, 2009 at 9:23 AM, Matthias Kestenholz 
> mailto:matthias.kestenh...@gmail.com>> 
> wrote:
> 
> thread locals have all the problems which are generally associated
> with global variables. They might be overwritten by other code, they
> make testing extremely difficult because the behavior of methods may
> depend on non-obvious circumstances and it's not clear from the method
> signatures which variables are really used -- in short, it makes code
> maintenance much harder than it needs to be.
> 
> I'll try giving a few examples:
> 
> - You have a field on your model called last_modified_by, and you
> automatically assign request.user in the save() method. You made this
> piece of code much harder to test in an unittest than it needs to be,
> because now you have to provide the complete environment including the
> variables from the threadlocals space in your testsuite. More code is
> needed, and the probability that the code and the testsuite (and
> eventual documentation) get out of sync gets bigger and bigger.
> 
> - Something which I've done for a CRM system which we've developped
> for internal use together with another company was giving Tasks access
> levels, so that we were able to make certain tasks viewable only by
> the management. I built a manager which uses the user information from
> thread local space to filter the queryset automatically according to
> the profile of the currently authenticated user. With this seemingly
> simple move I've made it impossible to use loaddata/dumpdata, because
> no user exists, and I made it very non-obvious that the list of
> viewable tasks depends on the user. You would not get the idea that
> filtering is going on in the templates or even in a big part of the
> code. This is not a big problem when developping alone, but it can
> really hamper progress if someone else takes over the codebase.
> 
> In short: It's easy and it gets the job done, but will come back and
> bite you later for sure. Don't give in to the temptation -- it's much
> better to write custom template tags where you can pass the user
> explicitly to the function, which makes it very clear that the
> output/the result of a certain function depends on the user. It also
> makes testing a breeze, because the behavior of methods is only
> determined by their arguments (as it should be), not by other
> circumstances or the current weather.
> 
> 
> Matthias, thanks. I really appreciate you taking the time to explain 
> that. I always wondered why the objected oriented world crucified 
> global variables. :o)
> 

In this case, I'd rather call it "environment variable", it sounds much 
better ;)

Bartek

> 
> > 


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



Search Field Problem

2009-07-21 Thread Harish

Hi Friends,

Just refer the sample code below.

My problem is I am referring a Dependant models field in
'search_field'
it is working correctly but when i delete a record from 'Dept' name
from Dept Model
the Search for the firstname is not working..
For example

The following data is displayed in the Employee Model

Employee
FirstName   |  Last Name  |  Dept   |
-
AAABBB   Sales
BBBCCC|  Purchase

Dept
DeptName |  Employee Name   |   Other Detail

Sales   AAA None
PurchaseBBB None

In the above example (data) if I Search for Employee 'AAA'
It produces the result. But When I delete the  'Purchase' record
from 'Dept' Table, and then  Search 'AAA' in 'Employee' Table
It is not displaying the Record. (The record exists in the list)

I want to display the records of Employee when there is no record
exist in the Dept Model with Dept as None

# Code Snippet
class Employee(models.Model):
   firstname = models.CharField(maxlength=80)
   last_name = models.CharField(maxlength=80)
   salary = models.DecimalField()

   def __str__  (self):
   return self.firstname

   def getdept(self):
try:
dept = Dept.objects.get(pk=self.pk)
except Dept.DoesNotExist:
dept = Dept()
return dept.dept_name

list_display = ('firstname  ','lastname','getdept')
search_fields = ['firstname','lastname','Dept__dept_name']



class Dept(models.Model):
   dept_name = models.CharField(maxlength=80)
   empName = models.OneToOneField(Employee, )
   otherDetails = models.TextField()

  def __str__   (self):
   return self.dept_name

  list_display = ('dept_name')
  search_fields = ['dept_name']



Kindly reply if anyone has solution to this??


Regards
Harish Bhat

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



Re: Windows development server problem

2009-07-21 Thread Daniel Roseman

On Jul 21, 12:13 am, cwurld  wrote:
> Hi,
>
> I have a snippet of code that runs fine as a standalone program. But
> when I incorporate it into a view and access that view w the
> development server, the snippet no longer works.
>
> What is the difference between the python interpreter and the
> development server?
>
> Thanks,
> Chuck

What does 'no longer works' mean? Does it do nothing at all, does it
give errors, does it do something unexpected, or what? Post the
traceback if you have one, and/or the snippet itself.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: combining valueslistqueryset with a simple list

2009-07-21 Thread V

thx

On Jul 20, 4:25 pm, Alex Gaynor  wrote:
> On Mon, Jul 20, 2009 at 6:48 AM, Viktor wrote:
>
> > Hi,
>
> > I would like to run something like
>
> > ["User",].expand(MyObject.objects.all().values_list('myfield',
> > flat=True)
>
> > but expand seemingly can't handle this operation.
> > I was trying MyValuesListQuerySet.insert, but it fails as well (This
> > is I can understand though. :))
>
> > could someone help me on the best way to combine a list with a
> > valueslistqueryset, please?
>
> > thx, V
>
> List's don't have a method named expand, they have one named extend
> and it should work fine.
>
> a = ['user']
> a.extend(valuelist_queryset)
> print a
> ['user',  ...]
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your
> right to say it." -- Voltaire
> "The people's good is the highest law." -- Cicero
> "Code can always be simpler than you think, but never as simple as you
> want" -- Me
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Retaining POST DATA

2009-07-21 Thread Tim Chase

>   I am sending POST data to a view But this view has login_required
> decorator enabled, So if i m user is not logged in, he goes to
> /accounts/login page and when user login, al the POST data is lost. Is there
> any way to maintain the actual POST data sent for view.


There was a long discussion[1] on this fairly recently.  The 
verdict is that it can be hacked, but it introduces a CSRF 
exploit.  The way around it (as I understand it) is to have it 
not carry over the actual submission, but rather just  carry over 
the data to pre-populate the form.  The user (now logged in) can 
confirm that this data really is what they entered (rather than 
nefarious data), and re-submit the form as a now-logged-in user.

-tim

[1]
http://groups.google.com/group/django-users/browse_thread/thread/15faa2c0a57c1adf/







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



Re: Search Field Problem

2009-07-21 Thread PanFei
may I have your version of django ?

On Tue, Jul 21, 2009 at 4:49 PM, Harish  wrote:

>
> Hi Friends,
>
> Just refer the sample code below.
>
> My problem is I am referring a Dependant models field in
> 'search_field'
> it is working correctly but when i delete a record from 'Dept' name
> from Dept Model
> the Search for the firstname is not working..
> For example
>
> The following data is displayed in the Employee Model
>
> Employee
> FirstName   |  Last Name  |  Dept   |
> -
> AAABBB   Sales
> BBBCCC|  Purchase
>
> Dept
> DeptName |  Employee Name   |   Other Detail
> 
> Sales   AAA None
> PurchaseBBB None
>
> In the above example (data) if I Search for Employee 'AAA'
> It produces the result. But When I delete the  'Purchase' record
> from 'Dept' Table, and then  Search 'AAA' in 'Employee' Table
> It is not displaying the Record. (The record exists in the list)
>
> I want to display the records of Employee when there is no record
> exist in the Dept Model with Dept as None
>
> # Code Snippet
> class Employee(models.Model):
>   firstname = models.CharField(maxlength=80)
>   last_name = models.CharField(maxlength=80)
>   salary = models.DecimalField()
>
>   def __str__  (self):
>   return self.firstname
>
>   def getdept(self):
>try:
>dept = Dept.objects.get(pk=self.pk)
>except Dept.DoesNotExist:
>dept = Dept()
>return dept.dept_name
>
>list_display = ('firstname  ','lastname','getdept')
>search_fields = ['firstname','lastname','Dept__dept_name']
>
>
>
> class Dept(models.Model):
>   dept_name = models.CharField(maxlength=80)
>   empName = models.OneToOneField(Employee, )
>   otherDetails = models.TextField()
>
>  def __str__   (self):
>   return self.dept_name
>
>  list_display = ('dept_name')
>  search_fields = ['dept_name']
>
>
>
> Kindly reply if anyone has solution to this??
>
>
> Regards
> Harish Bhat
>
> >
>

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



Re: Search Field Problem

2009-07-21 Thread Harish

The Django Version I am using is
'0.97-pre-SVN-7049'


On Jul 21, 2:56 pm, PanFei  wrote:
> may I have your version of django ?
>
> On Tue, Jul 21, 2009 at 4:49 PM, Harish  wrote:
>
> > Hi Friends,
>
> > Just refer the sample code below.
>
> > My problem is I am referring a Dependant models field in
> > 'search_field'
> > it is working correctly but when i delete a record from 'Dept' name
> > from Dept Model
> > the Search for the firstname is not working..
> > For example
>
> > The following data is displayed in the Employee Model
>
> > Employee
> > FirstName   |  Last Name  |  Dept   |
> > -
> > AAA            BBB           Sales
> > BBB            CCC        |  Purchase
>
> > Dept
> > DeptName     |  Employee Name   |   Other Detail
> > 
> > Sales           AAA                 None
> > Purchase        BBB                 None
>
> > In the above example (data) if I Search for Employee 'AAA'
> > It produces the result. But When I delete the  'Purchase' record
> > from 'Dept' Table, and then  Search 'AAA' in 'Employee' Table
> > It is not displaying the Record. (The record exists in the list)
>
> > I want to display the records of Employee when there is no record
> > exist in the Dept Model with Dept as None
>
> > # Code Snippet
> > class Employee(models.Model):
> >   firstname = models.CharField(maxlength=80)
> >   last_name = models.CharField(maxlength=80)
> >   salary = models.DecimalField()
>
> >   def __str__  (self):
> >       return self.firstname
>
> >   def getdept(self):
> >        try:
> >            dept = Dept.objects.get(pk=self.pk)
> >        except Dept.DoesNotExist:
> >            dept = Dept()
> >        return dept.dept_name
>
> >    list_display = ('firstname  ','lastname','getdept')
> >    search_fields = ['firstname','lastname','Dept__dept_name']
>
> > class Dept(models.Model):
> >   dept_name = models.CharField(maxlength=80)
> >   empName = models.OneToOneField(Employee, )
> >   otherDetails = models.TextField()
>
> >      def __str__       (self):
> >       return self.dept_name
>
> >      list_display = ('dept_name')
> >      search_fields = ['dept_name']
>
> > Kindly reply if anyone has solution to this??
>
> > Regards
> > Harish Bhat
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Search Field Problem

2009-07-21 Thread PanFei
oh my god ,I begin studying django  by using 1.02 



On Tue, Jul 21, 2009 at 6:06 PM, Harish  wrote:

>
> The Django Version I am using is
> '0.97-pre-SVN-7049'
>
>
> On Jul 21, 2:56 pm, PanFei  wrote:
> > may I have your version of django ?
> >
> > On Tue, Jul 21, 2009 at 4:49 PM, Harish  wrote:
> >
> > > Hi Friends,
> >
> > > Just refer the sample code below.
> >
> > > My problem is I am referring a Dependant models field in
> > > 'search_field'
> > > it is working correctly but when i delete a record from 'Dept' name
> > > from Dept Model
> > > the Search for the firstname is not working..
> > > For example
> >
> > > The following data is displayed in the Employee Model
> >
> > > Employee
> > > FirstName   |  Last Name  |  Dept   |
> > > -
> > > AAABBB   Sales
> > > BBBCCC|  Purchase
> >
> > > Dept
> > > DeptName |  Employee Name   |   Other Detail
> > > 
> > > Sales   AAA None
> > > PurchaseBBB None
> >
> > > In the above example (data) if I Search for Employee 'AAA'
> > > It produces the result. But When I delete the  'Purchase' record
> > > from 'Dept' Table, and then  Search 'AAA' in 'Employee' Table
> > > It is not displaying the Record. (The record exists in the list)
> >
> > > I want to display the records of Employee when there is no record
> > > exist in the Dept Model with Dept as None
> >
> > > # Code Snippet
> > > class Employee(models.Model):
> > >   firstname = models.CharField(maxlength=80)
> > >   last_name = models.CharField(maxlength=80)
> > >   salary = models.DecimalField()
> >
> > >   def __str__  (self):
> > >   return self.firstname
> >
> > >   def getdept(self):
> > >try:
> > >dept = Dept.objects.get(pk=self.pk)
> > >except Dept.DoesNotExist:
> > >dept = Dept()
> > >return dept.dept_name
> >
> > >list_display = ('firstname  ','lastname','getdept')
> > >search_fields = ['firstname','lastname','Dept__dept_name']
> >
> > > class Dept(models.Model):
> > >   dept_name = models.CharField(maxlength=80)
> > >   empName = models.OneToOneField(Employee, )
> > >   otherDetails = models.TextField()
> >
> > >  def __str__   (self):
> > >   return self.dept_name
> >
> > >  list_display = ('dept_name')
> > >  search_fields = ['dept_name']
> >
> > > Kindly reply if anyone has solution to this??
> >
> > > Regards
> > > Harish Bhat
> >
>

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



Re: django profiles :: choices form?

2009-07-21 Thread Léon Dignòn

You might take a look at this:
http://docs.djangoproject.com/en/dev/ref/models/fields/#ref-models-fields

models.py

class Foo(models.Model):
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)


On Jul 20, 11:24 pm, Saketh  wrote:
> Hi everyone,
>
> I am making a user settings page for my application based on django-
> registration and django-profiles, but I'm running into a small problem
> in how I'd like the page to be laid out.
>
> My data model has a field that can take on only three values, 'A',
> 'B', and 'C'. I have modeled this as a CharField with max_length=1.
> I'd like the generated form in the edit_profile view to be a list box
> with only those three options, rather than an actual character field,
> but I'm not able to figure out how to do this -- the closest thing
> I've found so far is 
> here:http://birdhouse.org/blog/2009/06/27/django-profiles/.
>
> Is there a way that I can use the list box to work with the three-
> valued field? Also, is there a more natural way to represent the
> finitely-valued field in the model itself?
>
> Thanks!
>
> -Saketh
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Foreign Keys

2009-07-21 Thread AKK

Do i need to have a one to many or many to many field for this to
work?

Thanks

Andrew

On 20 July, 22:24, AKK  wrote:
> Hello, i currently have two classes in my model:
>
> class Post(models.Model):
>     prepopulated_fields = {"post_slug": ("post_title",)}
>
>     post_title = models.CharField(max_length=750)
>     post_slug = models.SlugField()
>     
>
>  def __unicode__(self):
>         return self.post_title
>
> class Comment(models.Model):
>     comment_post = models.ForeignKey('Post')
>     comment_date = models.DateTimeField('Date comment made')
>     comment_body = models.TextField()
>     comment_spam = models.BooleanField(default=False)
>     comment_author = models.CharField(max_length=5000)
>
>     def __unicode__(self):
>         return unicode(self.comment_post)
>
> -
>
> And i want a view that returns the post and all the related comments.
> This is what i have:
>
> def title_view(request, slug):
>     blog_posts = Post.objects.filter(post_slug=slug)
>     blog_comments = Comment.objects.filter(some filter)
>     return render_to_response('blogSite/comments.html', locals(),
> context_instance=RequestContext(request))
>
> this is what i have, this returns the post but i don't know what
> filter to use to filter the comments, presuambly it should have
> something to do with comment_post since that is the foreign key but i
> don't know. I'd appreciate any help, i've tried doing it a number of
> ways with no success.
>
> Thanks,
>
> Andrew
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Foreign Keys

2009-07-21 Thread TiNo
On Mon, Jul 20, 2009 at 23:24, AKK  wrote:

>
> Hello, i currently have two classes in my model:
>
> class Post(models.Model):
>prepopulated_fields = {"post_slug": ("post_title",)}
>
>post_title = models.CharField(max_length=750)
>post_slug = models.SlugField()
>
>
>  def __unicode__(self):
>return self.post_title
>
>
> class Comment(models.Model):
>comment_post = models.ForeignKey('Post')
>comment_date = models.DateTimeField('Date comment made')
>comment_body = models.TextField()
>comment_spam = models.BooleanField(default=False)
>comment_author = models.CharField(max_length=5000)
>
>def __unicode__(self):
>return unicode(self.comment_post)
>
>
> -
>
> And i want a view that returns the post and all the related comments.
> This is what i have:
>
> def title_view(request, slug):
>blog_posts = Post.objects.filter(post_slug=slug)
>blog_comments = Comment.objects.filter(some filter)
>return render_to_response('blogSite/comments.html', locals(),
> context_instance=RequestContext(request))


You can access a posts comments through blog_posts.comment_set
Also see:
http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects

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



Django site on Apache

2009-07-21 Thread Kannan
Hi friends...
 I have downloaded the source of the
http://in.pycon.org/2009/from here
http://bitbucket.org/lawgon/fossconf/downloads/.
I try to run the site in my Apache server.
So i copy the extracted file to my /var/www/ directory named fossconf.

My apache2 conf file is here http://dpaste.com/69137/

when i try the url http://localhost/fossconf/  it gives error that "cannot
import the settings [Is this is in system path?"

Help me to solve this error.













With regards,

Kannan. R. P,

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



Re: Django admin doesn’t show translated enumerations in list view under Python 2.3

2009-07-21 Thread Ramiro Morales

On Mon, Jul 20, 2009 at 8:45 PM, Tomas Andrle wrote:
>
> When using localized list of "choices" for a model field, the admin
> doesn't show the translated values in the list view.
>
> Short example:
>
> from django.utils.translation import ugettext_lazy as _
>
> class OrderStates:
>    STATES = (
>        (STATE_NEW, _("New")),
>        (STATE_CANCELLED, _("Cancelled")), )
>
> class Order(models.Model):
>    state = models.IntegerField(choices=OrderStates.STATES)
>    # ..
>
> class OrderAdmin(admin.ModelAdmin):
>    list_display = [ 'id', 'state', 'address', 'user']
>    # ..
>
> admin.site.register(Order, OrderAdmin)
>
> The localized versions of "New" and "Cancelled" show up correctly in
> the front-end and in the admin form when editing an order.
>
> But in the admin list view I get blank fields - regardless of the
> language I switch to, including English. Column names are fine.
>
> This only happens with Python 2.3. The choices display correctly
> everywhere with Python 2.5. I don't get any errors or warnings in
> neither.
>
> Tried using ugettext instead of ugettext_lazy for the options, which
> didn't work. ugettext_noop sort of works - it at least shows the
> original english versions instead of blank fields.
>
> Am I doing something wrong or is this a bug?
>

I haven't acceso to a system with Python 2.3 anymore so
I can't do the following tests myself:

Would it be possible to run your test case both under:

* A checkout of Django from the 1.0.x SVN branch.
* A checkout of Django from the SVN trunk.

and see if there is any dfference?

-- 
Ramiro Morales
http://rmorales.net

PyCon 2009 Argentina - Vie 4 y Sab 5 Septiembre
Buenos Aires, Argentina
http://ar.pycon.org/2009/about/

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



Re: Search Field Problem

2009-07-21 Thread ankit rai
pls switch to django 1.1 beta version.You can easily download it from django
site

On Tue, Jul 21, 2009 at 3:47 PM, PanFei  wrote:

> oh my god ,I begin studying django  by using 1.02 
>
>
>
>
> On Tue, Jul 21, 2009 at 6:06 PM, Harish  wrote:
>
>>
>> The Django Version I am using is
>> '0.97-pre-SVN-7049'
>>
>>
>> On Jul 21, 2:56 pm, PanFei  wrote:
>> > may I have your version of django ?
>> >
>> > On Tue, Jul 21, 2009 at 4:49 PM, Harish 
>> wrote:
>> >
>> > > Hi Friends,
>> >
>> > > Just refer the sample code below.
>> >
>> > > My problem is I am referring a Dependant models field in
>> > > 'search_field'
>> > > it is working correctly but when i delete a record from 'Dept' name
>> > > from Dept Model
>> > > the Search for the firstname is not working..
>> > > For example
>> >
>> > > The following data is displayed in the Employee Model
>> >
>> > > Employee
>> > > FirstName   |  Last Name  |  Dept   |
>> > > -
>> > > AAABBB   Sales
>> > > BBBCCC|  Purchase
>> >
>> > > Dept
>> > > DeptName |  Employee Name   |   Other Detail
>> > > 
>> > > Sales   AAA None
>> > > PurchaseBBB None
>> >
>> > > In the above example (data) if I Search for Employee 'AAA'
>> > > It produces the result. But When I delete the  'Purchase' record
>> > > from 'Dept' Table, and then  Search 'AAA' in 'Employee' Table
>> > > It is not displaying the Record. (The record exists in the list)
>> >
>> > > I want to display the records of Employee when there is no record
>> > > exist in the Dept Model with Dept as None
>> >
>> > > # Code Snippet
>> > > class Employee(models.Model):
>> > >   firstname = models.CharField(maxlength=80)
>> > >   last_name = models.CharField(maxlength=80)
>> > >   salary = models.DecimalField()
>> >
>> > >   def __str__  (self):
>> > >   return self.firstname
>> >
>> > >   def getdept(self):
>> > >try:
>> > >dept = Dept.objects.get(pk=self.pk)
>> > >except Dept.DoesNotExist:
>> > >dept = Dept()
>> > >return dept.dept_name
>> >
>> > >list_display = ('firstname  ','lastname','getdept')
>> > >search_fields = ['firstname','lastname','Dept__dept_name']
>> >
>> > > class Dept(models.Model):
>> > >   dept_name = models.CharField(maxlength=80)
>> > >   empName = models.OneToOneField(Employee, )
>> > >   otherDetails = models.TextField()
>> >
>> > >  def __str__   (self):
>> > >   return self.dept_name
>> >
>> > >  list_display = ('dept_name')
>> > >  search_fields = ['dept_name']
>> >
>> > > Kindly reply if anyone has solution to this??
>> >
>> > > Regards
>> > > Harish Bhat
>>
>>
>
> >
>

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



Re: Problem sending json objects

2009-07-21 Thread Gustavo Henrique

Thanks, David!
I converted to string using:

str_obj = ''
$.each(obj, function(k, v) {
str_cols += '"'+k+'": "'+v+'",';
});
str_obj = '{'+str_obj.slice(0,-1)+'}';


-- 
Gustavo Henrique
Site: http://www.gustavohenrique.net
Blog: http://blog.gustavohenrique.net

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



Re: Template tags as parameter to template tag

2009-07-21 Thread David De La Harpe Golden

phoebebright wrote:
> Is there a way to get this to work:
> 
> {% for tag in tags %}
> {% tag_link
> "{{tag.name}}" %}
> {% endfor %}
> 
> 
> The outer loop is using the standard tagging application and the
> tag_link is my custom template tag which has a different url depending
> on the type of tag.
> I don't really want to amend the tagging app, so what is the correct
> way of doing this.  Extending the template tag class?
> 

Probab ly. I think the easiest thing might be to adjust tag_link
to take a context variable name argument so you just write e.g.

{% tag_link tag %}

- have your template tag look up the variable name passed
as an argument to tag_link (in this case tag_link would see
literally "tag") in the template context as per the django docs.

http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#passing-template-variables-to-the-tag

Then you should be able to do what you want based on that 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django site on Apache

2009-07-21 Thread Daniel Roseman

On Jul 21, 12:16 pm, Kannan  wrote:
> Hi friends...
>              I have downloaded the source of 
> thehttp://in.pycon.org/2009/fromherehttp://bitbucket.org/lawgon/fossconf/downloads/.
> I try to run the site in my Apache server.
> So i copy the extracted file to my /var/www/ directory named fossconf.
>
> My apache2 conf file is herehttp://dpaste.com/69137/
>
> when i try the urlhttp://localhost/fossconf/ it gives error that "cannot
> import the settings [Is this is in system path?"
>
> Help me to solve this error.
>
> With regards,
>
> Kannan. R. P,

Only you can help yourself, and you do that by reading the
documentation:
http://docs.djangoproject.com/en/dev/howto/deployment/
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



SpatialRefSys

2009-07-21 Thread ckar...@googlemail.com

Hi,

i've posted this question already in the geodjango-group (http://
groups.google.com/group/geodjango/browse_thread/thread/
844c8c601f24cdf9?hl=en) but I think this should be a general django
question.

I have in my models:

class PointClass(...):

srid = models.ForeignKey(SpatialRefSys, default=4326)


Not I get in my Admin Panel the complete wkt-representation:

see http://static.karrie.info/media/srid.png

How to get just a list of srid.name in my admin panel???

For example:
srid.name = "WGS 84"

Thankx

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



Re: Retaining POST DATA

2009-07-21 Thread ckar...@googlemail.com

You should define in your template or view to enable/disable the
submit button if the user is logged in/logged out before sending POST
Data. But I think there should be a way to this what you want ;-)

On Jul 21, 7:57 am, Raashid Malik  wrote:
> hi all,
>
>   I am sending POST data to a view But this view has login_required
> decorator enabled, So if i m user is not logged in, he goes to
> /accounts/login page and when user login, al the POST data is lost. Is there
> any way to maintain the actual POST data sent for view.
>
> Regards,
> Raashid Malik

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



UnicodeEncodeError on admin site

2009-07-21 Thread Rodrigo Gomes
Hi,

I'm getting the error below when i'm trying to edit a non ascii value on the
admin site.
I tried to put # -*- coding: utf-8 -*- on my model file, tried to set
settings.FILE_CHARSET to 'utf-8' and I tried to put
 on the
admin page "change.form.html", but it didn't work.

Is there something that I forgot to do? Google didn't help me so much...In
fact, I don't know how to search =/

Can you help me with this?

Exception Value:

Caught an exception while rendering: 'ascii' codec can't encode
character u'\xed' in position 9: ordinal not in range(128)

Original Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/django/template/debug.py",
line 71, in render_node

result = node.render(context)
  File "/Library/Python/2.5/site-packages/django/template/debug.py",
line 87, in render
output = force_unicode(self.filter_expression.resolve(context))
  File "/Library/Python/2.5/site-packages/django/template/__init__.py",
line 559, in resolve

new_obj = func(obj, *arg_vals)
  File "/Library/Python/2.5/site-packages/django/template/defaultfilters.py",
line 38, in _dec
args[0] = force_unicode(args[0])
  File "/Library/Python/2.5/site-packages/django/utils/encoding.py",
line 52, in force_unicode

s = unicode(str(s), encoding, errors)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in
position 9: ordinal not in range(128)


Thanks,
Rodrigo Gomes

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



TransactionMiddleware not working

2009-07-21 Thread Parag Shah
Hello,

Hello,

I am using TransactionMiddleware to get per request transactions working in
my Django project. However, it does not seem to be working.

I have a view in which I save an object and when I try to save a related
object there is an Exception. However, the first object is still saved.
Please find my code at: http://pastebin.com/f5b498b16

The topic_add(...) method is a view method which results in adding 3 rows
when a topic is added to a course:
1. Add the topic to the courses_topic table
2. Add a row to the courses_topic_courses table (because there is a
many-to-many relationship between Topic and Course)
3. Add a row to the courses_topicorder table

I deliberately introduced an error before step 3, yet step 1 and 2 were
carried out successfully.

Any help is appreciated.

--
Thanks & Regards
Parag Shah

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



Re: Model inheritance problem, inherited instances

2009-07-21 Thread Rodrigue

If you look here http://docs.djangoproject.com/en/dev/topics/db/models/#id7
you'll see that multi-table inheritance is handled at the db level
"via an automatically-created OneToOneField". This means that an
instance of B has a foreign key to an instance of A.

At the model level, there should be an a_ptr and an a_ptr_id
attributes (check with a dir(b) for example). The first one is the
instance of A associated with b, and the second the id of that
instance of A. So, I imagine that:
b = B()
b.a_ptr = a
b.save()

or

b = B()
b.a_ptr_id = a_id
b.save()

should do what you want.

Rodrigue
On Jul 20, 4:03 pm, Peter Cicman  wrote:
> Hi, i didn't found noting about it in docs, so i'll try to ask, first
> explanation, i have:
>
> class A(models.Model):
>     name = models.CharFiled(, required=True)
>     .
>
> class B(A):
>     
>
> I have an existing instance of A, say `a`
>
> and i "want to make" instance of b out of it.
>
> i'm looking for something like:
>     b = B()
>     b.origin = a
>     b.save()
>
> Is this somehow possible?
>
> Thanks a lot!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



middleware cache problem

2009-07-21 Thread Norman

Hi all,

I cache my view that show a list of stories, but I have also small
voting button (like digg). Voting is done be middleware class (it
reads user IP), so I can ask for view with list of stories and tell
that this list shall be cached and I have to ask middleware for vote
results.

Unfortunaltely when cache is ON my middleware voting class isn't asked
for voting results.

What can I do to mix cache from view and live results from my
middleware voting class?

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



Re: UnicodeEncodeError on admin site

2009-07-21 Thread Daniel Roseman

On Jul 21, 1:27 pm, Rodrigo Gomes  wrote:
> Hi,
>
> I'm getting the error below when i'm trying to edit a non ascii value on the
> admin site.
> I tried to put # -*- coding: utf-8 -*- on my model file, tried to set
> settings.FILE_CHARSET to 'utf-8' and I tried to put
>  on the
> admin page "change.form.html", but it didn't work.
>
> Is there something that I forgot to do? Google didn't help me so much...In
> fact, I don't know how to search =/
>
> Can you help me with this?
>
> Exception Value:
>
> Caught an exception while rendering: 'ascii' codec can't encode
> character u'\xed' in position 9: ordinal not in range(128)
>
> Original Traceback (most recent call last):
>   File "/Library/Python/2.5/site-packages/django/template/debug.py",
> line 71, in render_node
>
>     result = node.render(context)
>   File "/Library/Python/2.5/site-packages/django/template/debug.py",
> line 87, in render
>     output = force_unicode(self.filter_expression.resolve(context))
>   File "/Library/Python/2.5/site-packages/django/template/__init__.py",
> line 559, in resolve
>
>     new_obj = func(obj, *arg_vals)
>   File "/Library/Python/2.5/site-packages/django/template/defaultfilters.py",
> line 38, in _dec
>     args[0] = force_unicode(args[0])
>   File "/Library/Python/2.5/site-packages/django/utils/encoding.py",
> line 52, in force_unicode
>
>     s = unicode(str(s), encoding, errors)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in
> position 9: ordinal not in range(128)
>
> Thanks,
> Rodrigo Gomes

What encoding do your database and table have?
Also, it would help to post your model code - you may have a method
that's not returning unicode when it should be.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How I run background processes

2009-07-21 Thread Philippe Josse
Hi there,

I would like to have your feedback on the way I am running daemon scripts
for my Django/ Python app. I know this is definitely not the "one best way",
but this is a solution I came up with that seemed simple to implement. (I am
a real newbie!)

My constraints:
 - getting a few processs constantly repeating themselves
 - getting an email notification if one of the process crashes

I set up a cron job that is launching a "daemon manager" script every
minute. This script is querying a PostGreSQL database to retrieve boolean
values associated to the state of my background processes (running / not
running).  If the database indicates the process is not running, then the
cron script launches it.

Boolean values are updated by each process when it starts and finishes.
Currently, it seems to work fine - but my background processes are very
quick to execute. When my user base will grow, they may last longer and it
will be essential that background processes do not run concurrently.

Would that solution work? I was worried by potential caching issues with the
database that may prevent my cron script to retrieve the latest boolean
value. Is there any real risk?


Thanks for your feedback!

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



Re: middleware cache problem

2009-07-21 Thread Michael
On Tue, Jul 21, 2009 at 9:02 AM, Norman  wrote:

>
> Hi all,
>
> I cache my view that show a list of stories, but I have also small
> voting button (like digg). Voting is done be middleware class (it
> reads user IP), so I can ask for view with list of stories and tell
> that this list shall be cached and I have to ask middleware for vote
> results.
>
> Unfortunaltely when cache is ON my middleware voting class isn't asked
> for voting results.
>
> What can I do to mix cache from view and live results from my
> middleware voting class?


>From the per-site cache docs
http://docs.djangoproject.com/en/dev/topics/cache/#the-per-site-cache:

New in Django 1.0: Please, see the release
notes<../../releases/1.0/#releases-1-0>
If a view sets its own cache expiry time (i.e. it has a max-age section in
its Cache-Control header) then the page will be cached until the expiry
time, rather than CACHE_MIDDLEWARE_SECONDS. Using the decorators in
django.views.decorators.cache you can easily set a view's expiry time (using
the cache_control decorator) or disable caching for a view (using the
never_cache decorator). See the using other
headers<#controlling-cache-using-other-headers> section
for more on these decorators.


So all you need to do is make the cache on the view different (never_cache
decorator might be good here).

Read more on that page for the per-view cache.

Hope that helps,

Michael

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



Re: Django site on Apache

2009-07-21 Thread Kannan
>Only you can help yourself, and you do that by reading the
>documentation:
>http://docs.djangoproject.com/en/dev/howto/deployment/



I read the documentation of that and configure  all the settings.
that settings work in Fedora 10 but not work in Debian Lenny.
help me






With regards,

Kannan. R. P,



On Tue, Jul 21, 2009 at 6:06 PM, Daniel Roseman wrote:

>
> On Jul 21, 12:16 pm, Kannan  wrote:
> > Hi friends...
> >  I have downloaded the source of thehttp://
> in.pycon.org/2009/fromherehttp://bitbucket.org/lawgon/fossconf/downloads/.
> > I try to run the site in my Apache server.
> > So i copy the extracted file to my /var/www/ directory named fossconf.
> >
> > My apache2 conf file is herehttp://dpaste.com/69137/
> >
> > when i try the urlhttp://localhost/fossconf/ it gives error that "cannot
> > import the settings [Is this is in system path?"
> >
> > Help me to solve this error.
> >
> > With regards,
> >
> > Kannan. R. P,
>
> Only you can help yourself, and you do that by reading the
> documentation:
> http://docs.djangoproject.com/en/dev/howto/deployment/
> --
> DR.
> >
>

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



Filtered ManyToMany list in admin?

2009-07-21 Thread kaosbunny

Hello!

I'm fairly new to Python and Django and have mostly focused on the
admin system so far, but I am a programmer with fairly deep html/css/
javascript knowledge.

I was wondering if it's possible to filter the list generated in admin
forms for a ManyToMany field in a model.

Ideally I would like a ForeignKey field (also a property of the model)
affect what choices are visible.
For example: If I in the ForeignKey-dropdown select an office name,
the ManyToMany field would get populated with only the branches from
that specific office instead of all branches in the database.

Is this best done via template changes (adding javascript)? Or through
creating my own Widget? Or is it even possible to do it natively in
the model or admin definitions?

/KB

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



Re: How I run background processes

2009-07-21 Thread Andrew Fong

>> I was worried by potential caching issues with the database that
>> may prevent my cron script to retrieve the latest boolean value.

It sounds as if you're worried about a race condition when scale up --
e.g. let's say you need to run a lot of background processes and
decide to split them up among several machines, each with their own
cron jobs. If Machine A's cron job and Machine B's cron job both check
the database at the same time, they'll both see that the process isn't
running and start it up -- resulting in two copies of the process
instead of just one.

Am I correct in saying that's what you're concerned about?

If so, a simple solution would be to just wrap that part of the code
in a transaction. This will ensure Machine B doesn't get a response
back from the database until Machine A finishes updating it.

Aside from that, this seems fine.

-- Andrew

On Jul 21, 9:10 am, Philippe Josse  wrote:
> Hi there,
>
> I would like to have your feedback on the way I am running daemon scripts
> for my Django/ Python app. I know this is definitely not the "one best way",
> but this is a solution I came up with that seemed simple to implement. (I am
> a real newbie!)
>
> My constraints:
>  - getting a few processs constantly repeating themselves
>  - getting an email notification if one of the process crashes
>
> I set up a cron job that is launching a "daemon manager" script every
> minute. This script is querying a PostGreSQL database to retrieve boolean
> values associated to the state of my background processes (running / not
> running).  If the database indicates the process is not running, then the
> cron script launches it.
>
> Boolean values are updated by each process when it starts and finishes.
> Currently, it seems to work fine - but my background processes are very
> quick to execute. When my user base will grow, they may last longer and it
> will be essential that background processes do not run concurrently.
>
> Would that solution work? I was worried by potential caching issues with the
> database that may prevent my cron script to retrieve the latest boolean
> value. Is there any real risk?
>
> Thanks for your feedback!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: never_cache doesn't work for login page

2009-07-21 Thread Ronghui Yu
Eugene Mirotin ??:
> May be the order of middleware classes does matter here?
>
> On Jul 19, 4:08 pm, Ronghui Yu  wrote:
>   
>> It proves that it is introduced by
>> django.middleware.http.ConditionalGetMiddleware. It returns 304 when
>> requesting the same login page, so at last the browser uses the former one.
>> It works fine after removing this middleware.
>> I believe this middleware cannot work with never_cache.
>>
>> Eugene Mirotin ??:
>>
>>
>>
>> 
>>> Isn't adding a timestamp to the url a workaround?
>>> I mean making all links to /login/ look like /login/?_=timestamp
>>> This can be easily done on the client side with some JS library, or,
>>> on the server side.
>>>   
>>> Not nice, but it should help, I guess.
>>>   
>>> On Jul 17, 5:24 pm, Ronghui Yu  wrote:
>>>   
 Hi, All,
 
 I have a project that have CsrfMiddleware enable, all forms work fine,
 but the login form doesn't, for all browsers(IE,Chrome,Firefox,Safari).
 Most of the time, it throws 403, which is thrown by CsrfMiddleware.
 That's because the browser cache the login page, so each time the login
 page is opened, the csrfmiddlearetoken value doesn't get update. If the
 browser cache is cleaned before opening the login page, then it works
 fine. But this is not what I expect.
 
 When look into django.contrib.auth.views, the login view is decorated by
 never_cache, but actually it doesn't work for me. I have no idea what's
 wrong with it. Has anybody ever encounted this situation? Or could
 anybody give me some hints?
 
 Thanks in advance.
 
 --
 Ronghui Yu 
 
>> --
>> Ronghui Yu 
>> 
I had tried to reorder the middlewares, but it didn't work either.
Here is the comment of ConditionalGetMiddleware:

  5 Handles conditional GET operations. If the response has a ETag or
  6 Last-Modified header, and the request has If-None-Match or
  7 If-Modified-Since, the response is replaced by an HttpNotModified.
  8
  9 Also sets the Date and Content-Length response-headers.

I think the login page falls into this scope even it is decorated by 
never_cache.

-- 
Ronghui Yu 

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



Re: Django site on Apache

2009-07-21 Thread Andrew Fong

The documentation is distribution agnostic, so I'm not sure what
you're referring to. It sounds as if you just dropped a Django project
into /var/www and expected it to work. Unfortunately, Django is not
PHP. I'm going to assume you're unfamiliar with how Django works, so
apologies if you already read this, but I recommend starting here.

http://www.djangobook.com/en/2.0/chapter02/

And then reading the chapter on deployment here:

http://www.djangobook.com/en/2.0/chapter12/


-- Andrew



On Jul 21, 9:19 am, Kannan  wrote:
> >Only you can help yourself, and you do that by reading the
> >documentation:
> >http://docs.djangoproject.com/en/dev/howto/deployment/
>
>         I read the documentation of that and configure  all the settings.
> that settings work in Fedora 10 but not work in Debian Lenny.
> help me
>
> With regards,
>
> Kannan. R. P,
>
> On Tue, Jul 21, 2009 at 6:06 PM, Daniel Roseman wrote:
>
>
>
>
>
> > On Jul 21, 12:16 pm, Kannan  wrote:
> > > Hi friends...
> > >              I have downloaded the source of thehttp://
> > in.pycon.org/2009/fromherehttp://bitbucket.org/lawgon/fossconf/downloads/.
> > > I try to run the site in my Apache server.
> > > So i copy the extracted file to my /var/www/ directory named fossconf.
>
> > > My apache2 conf file is herehttp://dpaste.com/69137/
>
> > > when i try the urlhttp://localhost/fossconf/it gives error that "cannot
> > > import the settings [Is this is in system path?"
>
> > > Help me to solve this error.
>
> > > With regards,
>
> > > Kannan. R. P,
>
> > Only you can help yourself, and you do that by reading the
> > documentation:
> >http://docs.djangoproject.com/en/dev/howto/deployment/
> > --
> > DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: TransactionMiddleware not working

2009-07-21 Thread Andrew Fong

Just double checking, but are you using a DB that supports
transactions?

On Jul 21, 8:16 am, Parag Shah  wrote:
> Hello,
>
> Hello,
>
> I am using TransactionMiddleware to get per request transactions working in
> my Django project. However, it does not seem to be working.
>
> I have a view in which I save an object and when I try to save a related
> object there is an Exception. However, the first object is still saved.
> Please find my code at:http://pastebin.com/f5b498b16
>
> The topic_add(...) method is a view method which results in adding 3 rows
> when a topic is added to a course:
> 1. Add the topic to the courses_topic table
> 2. Add a row to the courses_topic_courses table (because there is a
> many-to-many relationship between Topic and Course)
> 3. Add a row to the courses_topicorder table
>
> I deliberately introduced an error before step 3, yet step 1 and 2 were
> carried out successfully.
>
> Any help is appreciated.
>
> --
> Thanks & Regards
> Parag Shah
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: TransactionMiddleware not working

2009-07-21 Thread Parag Shah
Hi Andrew,

I am using MySql. I believe it does support transactions. Here is the
version line of my instance of MySql

$mysql -V
mysql  Ver 14.12 Distrib 5.0.67, for debian-linux-gnu (x86_64) using
readline 5.2

--
Thanks & Regards
Parag Shah

On Tue, Jul 21, 2009 at 7:16 PM, Andrew Fong  wrote:

>
> Just double checking, but are you using a DB that supports
> transactions?
>
>

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



Re: pre-fetch one-to-many and many-to-many relationships

2009-07-21 Thread Miriam

Hi Russ --

Awesome. I will organize my ideas and start a thread over on django-
developers.

> I've heard people claim that
> this is possible in Rails (also in SQLAlchemy), but I've never had
> enough of an itch to go looking and see if this is true, and if so,
> how they implement it.

This is very much possible in Rails, and I'm pretty familiar w/ the
specifics of the implementation there. I made extensive use (and hit
some limitations) of this feature while working on a particularly
convoluted legacy project.

It's documented here (scroll down to the heading, "eager loading of
assocations"):
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

> There is a very old ticket - #2238 - which was marked 'wontfix' at the
> time for the same reasons I mentioned. I'm not aware of much by way of
> old discussions to build on, so feel free to start from scratch.

Thanks for digging that up. I guess there really isn't that much prior
art on the subject.

> Like I said - if you're keen to try to implement this, the next step
> is a thread on django-developers, in which you describe your proposal.

Will do. Thanks!

Miriam


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



Re: TransactionMiddleware not working

2009-07-21 Thread Hank Gay

Not all of the storage engines in MySQL support transactions, e.g.,
MyISAM doesn't.

On Tue, Jul 21, 2009 at 9:54 AM, Parag Shah wrote:
> Hi Andrew,
>
> I am using MySql. I believe it does support transactions. Here is the
> version line of my instance of MySql
>
> $mysql -V
> mysql  Ver 14.12 Distrib 5.0.67, for debian-linux-gnu (x86_64) using
> readline 5.2
>
> --
> Thanks & Regards
> Parag Shah
>
> On Tue, Jul 21, 2009 at 7:16 PM, Andrew Fong  wrote:
>>
>> Just double checking, but are you using a DB that supports
>> transactions?
>>
>
>
> >
>

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



Re: TransactionMiddleware not working

2009-07-21 Thread Randy Barlow

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Parag Shah declared:
> I am using MySql. I believe it does support transactions.

MySQL only supports transactions if you are using INNODB tables.  This
is not the default.

- --
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkplzMAACgkQw3vjPfF7QfWmzwCfY/kP3fEltHzOEfBQc/BZ+HrN
ufAAnjgRqhFwDbPym+4fo1NxiR1mrBgu
=mSLk
-END PGP SIGNATURE-

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



Re: UnicodeEncodeError on admin site

2009-07-21 Thread Rodrigo Gomes
Hi Daniel,

My databse enconding (Mysql) is utf-8, as you can see below:

Server characterset:latin1
Db characterset:utf8
Client characterset:latin1
Conn.  characterset:latin1

There is something strange, because I'm showing the same information on my
page and I'm not getting that error that I showed before.

The difference is that in my page I put  (without this I get the error)

My model code It's just mapping the database fields to python code, just
like this:
(the class and variable names are in Portuguese)

Is it missing something?

*from django.db import models

class PresenteRecebido(models.Model):
nome_convidado = models.CharField(max_length=60)
data_recebimento = models.DateField()
email = models.EmailField()
descricao_presente = models.CharField(max_length=300)
ip = models.CharField(max_length=100)

def __str__(self):
return self.nome_convidado + " - " + self.descricao_presente*




On Tue, Jul 21, 2009 at 10:05 AM, Daniel Roseman wrote:

>
> On Jul 21, 1:27 pm, Rodrigo Gomes  wrote:
> > Hi,
> >
> > I'm getting the error below when i'm trying to edit a non ascii value on
> the
> > admin site.
> > I tried to put # -*- coding: utf-8 -*- on my model file, tried to set
> > settings.FILE_CHARSET to 'utf-8' and I tried to put
> >  on
> the
> > admin page "change.form.html", but it didn't work.
> >
> > Is there something that I forgot to do? Google didn't help me so
> much...In
> > fact, I don't know how to search =/
> >
> > Can you help me with this?
> >
> > Exception Value:
> >
> > Caught an exception while rendering: 'ascii' codec can't encode
> > character u'\xed' in position 9: ordinal not in range(128)
> >
> > Original Traceback (most recent call last):
> >   File "/Library/Python/2.5/site-packages/django/template/debug.py",
> > line 71, in render_node
> >
> > result = node.render(context)
> >   File "/Library/Python/2.5/site-packages/django/template/debug.py",
> > line 87, in render
> > output = force_unicode(self.filter_expression.resolve(context))
> >   File "/Library/Python/2.5/site-packages/django/template/__init__.py",
> > line 559, in resolve
> >
> > new_obj = func(obj, *arg_vals)
> >   File
> "/Library/Python/2.5/site-packages/django/template/defaultfilters.py",
> > line 38, in _dec
> > args[0] = force_unicode(args[0])
> >   File "/Library/Python/2.5/site-packages/django/utils/encoding.py",
> > line 52, in force_unicode
> >
> > s = unicode(str(s), encoding, errors)
> > UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in
> > position 9: ordinal not in range(128)
> >
> > Thanks,
> > Rodrigo Gomes
>
> What encoding do your database and table have?
> Also, it would help to post your model code - you may have a method
> that's not returning unicode when it should be.
> --
> DR.
> >
>

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



Re: middleware cache problem

2009-07-21 Thread Norman

per-view cache is not a solution because I need only a method to
retrieve fresh (not cached) data from middleware.

I wanna take cached list of stories and not cached vote results for
it.

regards, Norman



On Jul 21, 3:13 pm, Michael  wrote:
> On Tue, Jul 21, 2009 at 9:02 AM, Norman  wrote:
>
> > Hi all,
>
> > I cache my view that show a list of stories, but I have also small
> > voting button (like digg). Voting is done be middleware class (it
> > reads user IP), so I can ask for view with list of stories and tell
> > that this list shall be cached and I have to ask middleware for vote
> > results.
>
> > Unfortunaltely when cache is ON my middleware voting class isn't asked
> > for voting results.
>
> > What can I do to mix cache from view and live results from my
> > middleware voting class?
>
> From the per-site cache 
> docshttp://docs.djangoproject.com/en/dev/topics/cache/#the-per-site-cache:
>
> New in Django 1.0: Please, see the release
> notes<../../releases/1.0/#releases-1-0>
> If a view sets its own cache expiry time (i.e. it has a max-age section in
> its Cache-Control header) then the page will be cached until the expiry
> time, rather than CACHE_MIDDLEWARE_SECONDS. Using the decorators in
> django.views.decorators.cache you can easily set a view's expiry time (using
> the cache_control decorator) or disable caching for a view (using the
> never_cache decorator). See the using other
> headers<#controlling-cache-using-other-headers> section
> for more on these decorators.
>
> So all you need to do is make the cache on the view different (never_cache
> decorator might be good here).
>
> Read more on that page for the per-view cache.
>
> Hope that helps,
>
> Michael
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Foreign Keys

2009-07-21 Thread AKK

Thanks, i tried this:

blog_posts = Post.objects.filter(post_slug=slug)
blog_comments = blog_posts.comment_set.all()

but i got this error and i don't know why:

Traceback:
File "C:\ProgLangs\Python25\lib\site-packages\django\core\handlers
\base.py" in get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "C:/Program Files/Apache2.2\akonline\blog\views.py" in title_view
  17. blog_comments = blog_posts.comment_set.all()

Exception Type: AttributeError at /blog/first_post/
Exception Value: 'QuerySet' object has no attribute 'comment_set'

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



Re: Foreign Keys

2009-07-21 Thread Daniel Roseman

On Jul 21, 4:25 pm, AKK  wrote:
> Thanks, i tried this:
>
> blog_posts = Post.objects.filter(post_slug=slug)
> blog_comments = blog_posts.comment_set.all()
>
> but i got this error and i don't know why:
>
> Traceback:
> File "C:\ProgLangs\Python25\lib\site-packages\django\core\handlers
> \base.py" in get_response
>   86.                 response = callback(request, *callback_args,
> **callback_kwargs)
> File "C:/Program Files/Apache2.2\akonline\blog\views.py" in title_view
>   17.     blog_comments = blog_posts.comment_set.all()
>
> Exception Type: AttributeError at /blog/first_post/
> Exception Value: 'QuerySet' object has no attribute 'comment_set'
>
> Andrew

You can't do it on the whole blog_posts queryset, you have to do it on
each blog_post object within the queryset.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Don't understand ModelForm

2009-07-21 Thread mettwoch

Hi,

I'd like to implement a simple "create" & "update" form for my
"Partner" model using ModelForm. How can I make the difference in a
view "save" function whether the POST comes from a "creation" or an
"update" form? Unfortunately the primary-key seems never to be
included by default in the form fields! This would have made it easy.

Got 3 view functions:
new(request):
   

edit(request, partner):
   

save(request):
   http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Don't understand ModelForm

2009-07-21 Thread Shawn Milochik


On Jul 21, 2009, at 12:00 PM, mettwoch wrote:

>
> Hi,
>
> I'd like to implement a simple "create" & "update" form for my
> "Partner" model using ModelForm. How can I make the difference in a
> view "save" function whether the POST comes from a "creation" or an
> "update" form? Unfortunately the primary-key seems never to be
> included by default in the form fields! This would have made it easy.
>
> Got 3 view functions:
> new(request):
>   
>
> edit(request, partner):
>   
>
> save(request):
>update partner
>else:
>create partner
>
> Many thanks for any hint
> Marc
>
> >

You don't need the save version. Your edit form will save the object  
instance whether it's new or not, with the .save() method. This is one  
of the nice things about Django models -- it simplifies things. If you  
need to do something differently depending on whether the object is  
being saved for the first time, you do it by overriding the save()  
method in the model itself.

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



Re: UnicodeEncodeError on admin site

2009-07-21 Thread Daniel Roseman

On Jul 21, 3:46 pm, Rodrigo Gomes  wrote:
> Hi Daniel,
>
> My databse enconding (Mysql) is utf-8, as you can see below:
>
> Server characterset:    latin1
> Db     characterset:    utf8
> Client characterset:    latin1
> Conn.  characterset:    latin1

But what about your actual tables? When you do 'SHOW CREATE TABLE
mytablename;', what does it show for the DEFAULT CHARSET value at the
end?

> There is something strange, because I'm showing the same information on my
> page and I'm not getting that error that I showed before.
>
> The difference is that in my page I put  content="text/html; charset=utf-8" /> (without this I get the error)
>
> My model code It's just mapping the database fields to python code, just
> like this:
> (the class and variable names are in Portuguese)
>
> Is it missing something?
>
> *from django.db import models
>
> class PresenteRecebido(models.Model):
>     nome_convidado = models.CharField(max_length=60)
>     data_recebimento = models.DateField()
>     email = models.EmailField()
>     descricao_presente = models.CharField(max_length=300)
>     ip = models.CharField(max_length=100)
>
>     def __str__(self):
>         return self.nome_convidado + " - " + self.descricao_presente*

Probably not the cause of the problem but you shouldn't be using
__str__, you should be using __unicode__. And you should make sure it
actually returns unicode:

def __unicode__(self):
return u'%s - %s' % (self.nome_convidado, self.descricao_presente)

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



inclusion_tag -- error

2009-07-21 Thread Buddy

Hi. I learn to inclusion_tag from django documentation. and i take
code from here. I try do it code: http://dpaste.com/69553/ but i get
error: http://dpaste.com/69555/  Where is my mistake?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Recommendations for a Django development book?

2009-07-21 Thread Stodge

What is currently the best Django development book? There seem to be
quite a few on Amazon.ca, but none are reviewed. I'm familiar with
Python and the very basics of Django and I've been developing s/w for
15+ years. So something geared towards advanced users would be good.
Much appreciated!

Thanks

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



Re: Template tags as parameter to template tag

2009-07-21 Thread Reiner

Maybe I'm missing something here, but what is wrong with this?

{% tag_link tag.name %}

The string "tag.name" gets passed to your template tag, you resolve it
against the current context when rendering it, and then you have the
value and can do whatever you want with it. See [1] for reference.

[1] 
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#passing-template-variables-to-the-tag

On Jul 20, 7:33 pm, phoebebright  wrote:
> Is there a way to get this to work:
>
>             {% for tag in tags %}
>                 {% tag_link
> "{{tag.name}}" %}
>             {% endfor %}
>
> The outer loop is using the standard tagging application and the
> tag_link is my custom template tag which has a different url depending
> on the type of tag.
> I don't really want to amend the tagging app, so what is the correct
> way of doing this.  Extending the template tag class?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Don't understand ModelForm

2009-07-21 Thread mettwoch

Sorry my old brain doesn't get it. Is there somewhere a complete CRUD
example using ModelForm?

Thanks
Marc

On Jul 21, 6:04 pm, Shawn Milochik  wrote:
> On Jul 21, 2009, at 12:00 PM, mettwoch wrote:
>
>
>
>
>
> > Hi,
>
> > I'd like to implement a simple "create" & "update" form for my
> > "Partner" model using ModelForm. How can I make the difference in a
> > view "save" function whether the POST comes from a "creation" or an
> > "update" form? Unfortunately the primary-key seems never to be
> > included by default in the form fields! This would have made it easy.
>
> > Got 3 view functions:
> > new(request):
> >   
>
> > edit(request, partner):
> >   
>
> > save(request):
> >    >         update partner
> >    else:
> >        create partner
>
> > Many thanks for any hint
> > Marc
>
> You don't need the save version. Your edit form will save the object  
> instance whether it's new or not, with the .save() method. This is one  
> of the nice things about Django models -- it simplifies things. If you  
> need to do something differently depending on whether the object is  
> being saved for the first time, you do it by overriding the save()  
> method in the model itself.
>
> 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Recommendations for a Django development book?

2009-07-21 Thread Masklinn

On 21 Jul 2009, at 18:36 , Stodge wrote:
> What is currently the best Django development book? There seem to be
> quite a few on Amazon.ca, but none are reviewed. I'm familiar with
> Python and the very basics of Django and I've been developing s/w for
> 15+ years. So something geared towards advanced users would be good.
> Much appreciated!

The second edition of Practical Django Projects? The first edition was  
good but hampered by being released soon before 1.0 yet tracking 0.96.  
The second edition tracks Django 1.1 so it doesn't have that issue  
(and since Django's API is now stable, it doesn't have the issue of  
broken code either).

On the other hand, PDP is light on the "under the hood" stuff. It  
isn't about how django works, it's about how to work with Django.

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



AnonymousUser and groups attribute

2009-07-21 Thread Frédéric Hébert

Hi there,

 I've a context_processor to automatically add to each template a
object which says to me if a given user is memeber of an admin group.
It works fine when user is authenticated (whichever groups he belongs
to) but raise an AttributeError when user is not.

"Nonetype has no attribute _meta" in models.query (get_meta method)

Here is my context_processor code :

--- CODE --

def is_gestion(request):

try:
return {'gestion': request.user.groups.get
(name=settings.BAOBAB_ADMIN_GROUP)}
except Group.DoesNotExist:
if request.user.is_superuser:
return {'gestion': True}
else:
return {'gestion': False}


- CODE ---

and here the my pasted trace :
http://dpaste.com/69576/

It appears that an AnonymousUser has an EmptyManager connected to its
groups attribute.

 AFAICS, this manager permits to keep the code applied to an
authenticated user valid even if an anonymous user is here.

 (eg we have more or less the same attributes on both User and
AnonymousUser objects).

 How can I handle the groups relation in this way ?

Thanks a lot

 Frédéric



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



Re: TransactionMiddleware not working

2009-07-21 Thread Parag Shah
Thanks for the help.

Transactions work just fine after changing MyISam to InnoDB.

--
Thanks & Regards
Parag Shah

On Tue, Jul 21, 2009 at 7:42 PM, Randy Barlow wrote:

>
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Parag Shah declared:
> > I am using MySql. I believe it does support transactions.
>
> MySQL only supports transactions if you are using INNODB tables.  This
> is not the default.
>
> - --
> Randy Barlow
> Software Developer
> The American Research Institute
> http://americanri.com
> 919.228.4971
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v2.0.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkplzMAACgkQw3vjPfF7QfWmzwCfY/kP3fEltHzOEfBQc/BZ+HrN
> ufAAnjgRqhFwDbPym+4fo1NxiR1mrBgu
> =mSLk
> -END PGP SIGNATURE-
>
>

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



Re: Making Django ldapauth more sophisticated

2009-07-21 Thread Frédéric Hébert



On 21 juil, 00:35, "Daniele Procida" 
wrote:
> I finally have ldapauth working now, and a user who is in our LDAP
> database can connect as a Django User.
>
> But it's not entirely satisfactory. Before the LDAP user becomes a
> Django User they have to try logging (which fails of course).

Are you talking about admin login or a custom login ?

 We use too a bind to ldap for authentication in admin and we've
directly setted is_staff to True in this bind; it works.

 The user is directly connected.

 The problem is now to get permissions from ldap :-)

Frédéric


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



admin add view saves two entries on submit

2009-07-21 Thread JP

Hi!
I'm not sure why this happens but when I save a model (that has a
foreign key) two identical entries are saved in the database (but
diffs in id of course..).
As there aren't really any errors I'm stumped on where to actually
start looking. Any ideas?

The models I made we're really simple tests. I don't have them here
right now but it's more or less something silly like this:

class Egg(models.Model):
e = models.CharField(...)

class Spam(models.Model):
   x = models.ForeignKey(Egg)
   name = models.CharField(...)

What I used:
Django 1.0.2 (tarball)
IE 6 (don't have a choice)
Python 2.5.4
Django dev. server
cx_Oracle 5.0.1

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



Re: Don't understand ModelForm

2009-07-21 Thread Shawn Milochik


On Jul 21, 2009, at 12:49 PM, mettwoch wrote:

>
> Sorry my old brain doesn't get it. Is there somewhere a complete CRUD
> example using ModelForm?
>
> Thanks
> Marc

CRUD:

If your modelform is called PartnerForm, then.

CREATE and UPDATE:

#on initial page load (no POST)

#if you have a partner object already (named partner_instance):
partner_form = PartnerForm(instance = partner_instance)
#otherwise:
partner_form = PartnerForm()

#in the POST portion of your view
partner_form = PartnerForm(request.POST)
if partner_form.is_valid():
partner_form.save()

DELETE:
#if you have a partner object named partner_instance
partner_instance.delete()

READ:
What do you mean?
Partner.objects.get(pk = 12) #or whatever

#or, from the modelform instance, assuming
#something like partner_form = PartnerForm(instance = partner_instance)
#has happened:
if partner_form.is_valid():
partner_name = partner_form.cleaned_data['name']

I hope this helps. If not, please be more specific.



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



Re: Recommendations for a Django development book?

2009-07-21 Thread Shawn Milochik

"The Definitive Guide to Django," second edition. It was just  
published and was written by Adrian Holovaty and Jacob Kaplan-Moss. In  
case you don't know who they are, they're the co-creator and a lead  
developer of Django, respectively.



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



Re: Don't understand ModelForm

2009-07-21 Thread mettwoch

Hi again,

That's exactly what I did and the point is that it doesn't work! See
my comments below ...

On Jul 21, 8:00 pm, Shawn Milochik  wrote:
> On Jul 21, 2009, at 12:49 PM, mettwoch wrote:
>
>
>
> > Sorry my old brain doesn't get it. Is there somewhere a complete CRUD
> > example using ModelForm?
>
> > Thanks
> > Marc
>
> CRUD:
>
> If your modelform is called PartnerForm, then.
>
> CREATE and UPDATE:
>
>         #on initial page load (no POST)
>
>         #if you have a partner object already (named partner_instance):
>         partner_form = PartnerForm(instance = partner_instance)
>         #otherwise:
>         partner_form = PartnerForm()
>
>         #in the POST portion of your view
>         partner_form = PartnerForm(request.POST)
>         if partner_form.is_valid():
>                 partner_form.save()

This always creates a new partner! In fact, in the ModelForm
documentation is written that the save() method creates a new instance
unless an existing instance is passed to the ModelForm constructor. So
one has to differentiate if the POST comes from an initially empty
form or from a bound form! How can this be done? I believe that it
could be easily achieved if the primary-key were always included as a
hidden field. If it's empty, then 'create' otherwise 'get' & 'update'.

>
> DELETE:
>         #if you have a partner object named partner_instance
>         partner_instance.delete()
>
> READ:
>         What do you mean?
>         Partner.objects.get(pk = 12) #or whatever

In my specific case the partner is stored in the session and it can be
updated. When a new partner is created it is stored in the session.
There's always an 'actif' partner.

>
>         #or, from the modelform instance, assuming
>         #something like partner_form = PartnerForm(instance = 
> partner_instance)
>         #has happened:
>         if partner_form.is_valid():
>                 partner_name = partner_form.cleaned_data['name']
>
> I hope this helps. If not, please be more specific.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Don't understand ModelForm

2009-07-21 Thread Shawn Milochik
>
> This always creates a new partner! In fact, in the ModelForm
> documentation is written that the save() method creates a new instance
> unless an existing instance is passed to the ModelForm constructor. So
> one has to differentiate if the POST comes from an initially empty
> form or from a bound form! How can this be done? I believe that it
> could be easily achieved if the primary-key were always included as a
> hidden field. If it's empty, then 'create' otherwise 'get' & 'update'.
>
>>
>> DELETE:
>> #if you have a partner object named partner_instance
>> partner_instance.delete()
>>
>> READ:
>> What do you mean?
>> Partner.objects.get(pk = 12) #or whatever


You are right, I made a mistake there. I typed it off of the top of my  
head, instead of copying and pasting from working code.

All you have to do is what I did above in the create -- have an if  
statement. If the partner already exists, you have to get
that object (using the Partner.objects.get(your_criteria_here) and  
pass it using the 'instance' keyword.

Something like:

#if it's an existing partner:
partner_form = PartnerForm(instance = partner_instance)

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



Re: Recommendations for a Django development book?

2009-07-21 Thread Dan Harris

You can always check out the free online Django book at: 
http://www.djangobook.com/
There is the 1.0 version (outdated) and a free web-preview of the 2nd
edition available.

In addition to books, the documentation for Django is pretty fantastic
to learn from for a beginner. This is located at: 
http://docs.djangoproject.com/en/dev/

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



Show related inlines in the admin on form of model with GenericForeignKey

2009-07-21 Thread ramu...@gmail.com

I have simple models with generic relations from this example at the
Django Project:

class Image(models.Model):
image = models.ImageField(upload_to="images")
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey("content_type",
"object_id")

class Product(models.Model):
name = models.CharField(max_length=100)

It's very simple to show inline objects on the admin form of Product.
It is demonstrated in the Django docs:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#using-generic-relations-as-an-inline.

Can anyone suggest how have related Products inline on the admin form
of an Image model?

Copy from here:
http://stackoverflow.com/questions/1160174/show-related-inlines-in-the-admin-on-form-of-model-with-genericforeignkey
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to make email field unique in model User from contrib.auth in Django

2009-07-21 Thread ramu...@gmail.com

I need to patch the standard User model of contrib.auth by ensuring
the email field entry is unique:

User._meta.fields[4].unique = True

Where is best place in code to do that?

I want to avoid using the number fields[4]. It's better to user fields
['email'], but fields is not dictionary, only list.

Another idea may be to open a new ticket and upload a patch with new
parameter inside settings.py:

AUTH_USER_EMAIL_UNIQUE = True

Any suggestions on the most correct way to achieve email address
uniqueness in the Django User model?

Copy from here:
http://stackoverflow.com/questions/1160030/how-to-make-email-field-unique-in-model-user-from-contrib-auth-in-django
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Don't understand ModelForm

2009-07-21 Thread mettwoch

Sorry to insist, but that's what I don't understand here. How can I
know that the partner that is 'posted' is new or not? I really become
crazy here. I can't believe after all the good things I've discovered
in Django that this can be so hard.

Thanks for your time
>
> You are right, I made a mistake there. I typed it off of the top of my  
> head, instead of copying and pasting from working code.
>
> All you have to do is what I did above in the create -- have an if  
> statement. If the partner already exists, you have to get
> that object (using the Partner.objects.get(your_criteria_here) and  
> pass it using the 'instance' keyword.
>
> Something like:
>
> #if it's an existing partner:
> partner_form = PartnerForm(instance = partner_instance)
>
> #else:
> partner_form = PartnerForm(request.POST)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Customizing context by opening up BoundField, is it ok?

2009-07-21 Thread Joshua Russo

I have a complex form that where I generate a grid (for lack of a
better term) of fields for data entry. To simplify the template
context I have a dictionaries within dictionaries so I can just use
FOR loops within FOR loops in the template.

My problem was that, unless I wrapped my fields in a BoundField, I
would only receive the field's object reference output instead of the
rendered widgets. So I added BoundField to the list of available
objects in forms.py and everything is hums along merrily.

My question is, am I breaking any Django commandments by opening up
the BoundField (other than not monkey patching)?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Don't understand ModelForm

2009-07-21 Thread Shawn Milochik


On Jul 21, 2009, at 3:39 PM, mettwoch wrote:

>
> Sorry to insist, but that's what I don't understand here. How can I
> know that the partner that is 'posted' is new or not? I really become
> crazy here. I can't believe after all the good things I've discovered
> in Django that this can be so hard.
>

Okay, thanks for clarifying.

Well, you can have the partner identified in the URL by a slug or  
something, for one. That's probably the easiest way. You do need to  
track it somehow, starting when you pull the instance from the  
database to populate the ModelForm. Otherwise, how can you know that  
it's someone new versus someone with the same details?

The way I'm doing it is by having separate views and urls for editing  
and creating a new entry. But in any case you have to write something  
somewhere when you are pulling an existing record. 

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



Re: Don't understand ModelForm

2009-07-21 Thread Dan Harris

This may not be helpful but here is how I usually go about processing
model forms:

class Partner(models.Model):
# this is your model, DB fields go in here

# This is your model form
class PartnerForm(forms.ModelForm):
   class Meta:
  model = Partner

# This is the view that displays a new partner form or processes the
form
def new(request):
form = PartnerForm()
if request.method=="POST":
# if there is a post, they are sending in the form so re-
create the form from the post data
form = PartnerForm(request.POST)
if form.is_valid():
 p = form.save()   # save the form and store the resulting
Partner object in p
 return HttpResponseRedirect("/success")  # always
redirect after processing a form to revent refresh spam

# if we got to this point it means it wasn't a POST and we didn't
process a form, or the form was invalid
   # either way, render whatever we had with errors and what not
return render_to_response('new_partner_template.html', {'form':
form})

# This is a view to edit and existing parter
def edit(request, id):   # ID is the partners identifying number such
as primary key, SSN, whatever you want
p = get_object_or_404(Partner, pk=id)   # this will throw a 404 if
they requested an invalid partner
form = PartnerForm(instance=p)   # create a form pre-populated
with the partner data we just loaded
if request.method=='POST':
# now process the submitted form
form = PartnerForm(request.POST, instance=p)   # this creats a
form using the database data AND the post data
if form.is_valid():
 p = form.save()
 return HttpResponseRedirect('/success')

# if we got down here, they didn't submit the form, or they did
and there were errors, so render it back
   return render_to_response('my_template.html', {'form': form})

This is how I do it, If you have any further questions I can try to
help. Please note this code was off the top of my head, so it may not
compile "out of the box"

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



Re: Don't understand ModelForm

2009-07-21 Thread mettwoch

Ok, I come back to what I wrote before. If the partner already exists
it has an id (primary-key or whatever). If it doesn't exist it has no
id. I'd just like to have the id in the form. Is it a bug, is
something missing here or am I completely on the wrong track. That's
basic database form handling. Well I could fallback to using Form
instead of ModelForm and maybe I'll manage to get that id in the form
as a hidden field or whatever, but I wonder how such basic things seem
impossible with the ModelForm.

Thanks for Your patience

Marc

On Jul 21, 9:55 pm, Shawn Milochik  wrote:
> On Jul 21, 2009, at 3:39 PM, mettwoch wrote:
>
>
>
> > Sorry to insist, but that's what I don't understand here. How can I
> > know that the partner that is 'posted' is new or not? I really become
> > crazy here. I can't believe after all the good things I've discovered
> > in Django that this can be so hard.
>
> Okay, thanks for clarifying.
>
> Well, you can have the partner identified in the URL by a slug or  
> something, for one. That's probably the easiest way. You do need to  
> track it somehow, starting when you pull the instance from the  
> database to populate the ModelForm. Otherwise, how can you know that  
> it's someone new versus someone with the same details?
>
> The way I'm doing it is by having separate views and urls for editing  
> and creating a new entry. But in any case you have to write something  
> somewhere when you are pulling an existing record.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Might have found a bug with manage.py

2009-07-21 Thread Some Guy

I have a model with a proxy subclass.  dumpdata saves an entry for
each of the superclass' and an additional entry for the proxy class
(with no fields) as well.

 loaddata then chokes on the superclasses constraints. Or is it
supposed to do this?

i.e.  (psuedocode..)

assume app = 'bar'

class a(Models.model):
   foo = models..DateTimeField(auto_now_add=True)

class b(a):
   class Meta:
  proxy = True

dumpdata gives me something like this...

[
  {"pk":1,
"model": "bar.a"
   "fields":{
   "foo":  "2009-07-02 12:48:13"
}
},
 {"pk":1,
"model": "bar.b"
   "fields":{}
},
]

Loaddata then chokes on import with an integrity error saying "foo can
not be null"



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



Re: Don't understand ModelForm

2009-07-21 Thread Dan Harris

What do you mean by having the ID "in" the form? I don't quite
understand what you are trying to do.

On Jul 21, 4:15 pm, mettwoch  wrote:
> Ok, I come back to what I wrote before. If the partner already exists
> it has an id (primary-key or whatever). If it doesn't exist it has no
> id. I'd just like to have the id in the form. Is it a bug, is
> something missing here or am I completely on the wrong track. That's
> basic database form handling. Well I could fallback to using Form
> instead of ModelForm and maybe I'll manage to get that id in the form
> as a hidden field or whatever, but I wonder how such basic things seem
> impossible with the ModelForm.
>
> Thanks for Your patience
>
> Marc
>
> On Jul 21, 9:55 pm, Shawn Milochik  wrote:
>
>
>
> > On Jul 21, 2009, at 3:39 PM, mettwoch wrote:
>
> > > Sorry to insist, but that's what I don't understand here. How can I
> > > know that the partner that is 'posted' is new or not? I really become
> > > crazy here. I can't believe after all the good things I've discovered
> > > in Django that this can be so hard.
>
> > Okay, thanks for clarifying.
>
> > Well, you can have the partner identified in the URL by a slug or  
> > something, for one. That's probably the easiest way. You do need to  
> > track it somehow, starting when you pull the instance from the  
> > database to populate the ModelForm. Otherwise, how can you know that  
> > it's someone new versus someone with the same details?
>
> > The way I'm doing it is by having separate views and urls for editing  
> > and creating a new entry. But in any case you have to write something  
> > somewhere when you are pulling an existing record.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Might have found a bug with manage.py

2009-07-21 Thread Some Guy

also...

Django version 1.1 beta 1 SVN-11082

On Jul 21, 1:22 pm, Some Guy  wrote:
> I have a model with a proxy subclass.  dumpdata saves an entry for
> each of the superclass' and an additional entry for the proxy class
> (with no fields) as well.
>
>  loaddata then chokes on the superclasses constraints. Or is it
> supposed to do this?
>
> i.e.  (psuedocode..)
>
> assume app = 'bar'
>
> class a(Models.model):
>    foo = models..DateTimeField(auto_now_add=True)
>
> class b(a):
>    class Meta:
>       proxy = True
>
> dumpdata gives me something like this...
>
> [
>   {"pk":1,
>     "model": "bar.a"
>        "fields":{
>            "foo":  "2009-07-02 12:48:13"
>         }
>     },
>  {"pk":1,
>     "model": "bar.b"
>        "fields":{}
>     },
> ]
>
> Loaddata then chokes on import with an integrity error saying "foo can
> not be null"
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Might have found a bug with manage.py

2009-07-21 Thread Some Guy

Nevermind, I should have checked trac first instead of searching this
group

found http://code.djangoproject.com/ticket/11429
and

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

I guess I'll have to be explicit with which models to dump

On Jul 21, 1:23 pm, Some Guy  wrote:
> also...
>
> Django version 1.1 beta 1 SVN-11082
>
> On Jul 21, 1:22 pm, Some Guy  wrote:
>
>
>
> > I have a model with a proxy subclass.  dumpdata saves an entry for
> > each of the superclass' and an additional entry for the proxy class
> > (with no fields) as well.
>
> >  loaddata then chokes on the superclasses constraints. Or is it
> > supposed to do this?
>
> > i.e.  (psuedocode..)
>
> > assume app = 'bar'
>
> > class a(Models.model):
> >    foo = models..DateTimeField(auto_now_add=True)
>
> > class b(a):
> >    class Meta:
> >       proxy = True
>
> > dumpdata gives me something like this...
>
> > [
> >   {"pk":1,
> >     "model": "bar.a"
> >        "fields":{
> >            "foo":  "2009-07-02 12:48:13"
> >         }
> >     },
> >  {"pk":1,
> >     "model": "bar.b"
> >        "fields":{}
> >     },
> > ]
>
> > Loaddata then chokes on import with an integrity error saying "foo can
> > not be null"
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: What editor do you use for .po files?

2009-07-21 Thread bittin
i also use PoEdit =)

On Fri, Jun 19, 2009 at 11:05 PM, Joshua Russo wrote:

>
> I started using PoEdit but it seems to thing that the .po files
> created by makemessages are malformed, or at least don't have all the
> right headers. Is there a better editor for Windows?
> >
> i

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



Re: Don't understand ModelForm

2009-07-21 Thread Shawn Milochik


On Jul 21, 2009, at 4:22 PM, Dan Harris wrote:

>
> What do you mean by having the ID "in" the form? I don't quite
> understand what you are trying to do.
>
> On Jul 21, 4:15 pm, mettwoch  wrote:
>> Ok, I come back to what I wrote before. If the partner already exists
>> it has an id (primary-key or whatever). If it doesn't exist it has no
>> id. I'd just like to have the id in the form. Is it a bug, is
>> something missing here or am I completely on the wrong track. That's
>> basic database form handling. Well I could fallback to using Form
>> instead of ModelForm and maybe I'll manage to get that id in the form
>> as a hidden field or whatever, but I wonder how such basic things  
>> seem
>> impossible with the ModelForm.
>>
>> Thanks for Your patience
>>
>> Marc
>>


What he's referring to is the fact that, if you're using a ModelForm,  
the model's ID is not available in the template.

And my answer to the question is that I use the ID (or a slug) in both  
the URL and in the form's "action" argument, so that
when it's submitted, you have the info you need in the request.

Just as a quick example:

(r'^patient/(?P[-\w]+)/$', 'view'),

This will pass the variable "slug" to the view, and the slug is used  
to identify the patient. If you don't use
slugs, the ID works just as well (although it makes for less friendly- 
looking URLs).



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



Re: Don't understand ModelForm

2009-07-21 Thread mettwoch

I'd like this to work:

class PartnerForm(forms.ModelForm):
class Meta:
model  = Partner  # I expect that all fields are included in
the form (the 'id' field as well)

def partner_new(request):
form = PartnerForm()
return render_to_response('pos.html', {'form': form},
RequestContext(request))

def partner_edit(request):
form = PartnerForm(instance = request.session['partner'])
return render_to_response('pos.html', {'form': form},
RequestContext(request))

def partner_save(request):
if request.POST.get('id', None):
form = PartnerForm(request.POST, instance = get_object_or_404
(Partner, pk = request.POST['id']))
else:
form = PartnerForm(request.POST)
if form.is_valid():
form.save()
return render_to_response('pos.html', {}, RequestContext
(request))
else:
return render_to_response('pos.html', {'form': form},
RequestContext(request))

here's an excerpt of the pos.html:

{% if form %}


{{ form.as_table }}



...

as I said: maybe I'm on the wrong track with ModelForm ...



On Jul 21, 10:22 pm, Dan Harris  wrote:
> What do you mean by having the ID "in" the form? I don't quite
> understand what you are trying to do.
>
> On Jul 21, 4:15 pm, mettwoch  wrote:
>
> > Ok, I come back to what I wrote before. If the partner already exists
> > it has an id (primary-key or whatever). If it doesn't exist it has no
> > id. I'd just like to have the id in the form. Is it a bug, is
> > something missing here or am I completely on the wrong track. That's
> > basic database form handling. Well I could fallback to using Form
> > instead of ModelForm and maybe I'll manage to get that id in the form
> > as a hidden field or whatever, but I wonder how such basic things seem
> > impossible with the ModelForm.
>
> > Thanks for Your patience
>
> > Marc
>
> > On Jul 21, 9:55 pm, Shawn Milochik  wrote:
>
> > > On Jul 21, 2009, at 3:39 PM, mettwoch wrote:
>
> > > > Sorry to insist, but that's what I don't understand here. How can I
> > > > know that the partner that is 'posted' is new or not? I really become
> > > > crazy here. I can't believe after all the good things I've discovered
> > > > in Django that this can be so hard.
>
> > > Okay, thanks for clarifying.
>
> > > Well, you can have the partner identified in the URL by a slug or  
> > > something, for one. That's probably the easiest way. You do need to  
> > > track it somehow, starting when you pull the instance from the  
> > > database to populate the ModelForm. Otherwise, how can you know that  
> > > it's someone new versus someone with the same details?
>
> > > The way I'm doing it is by having separate views and urls for editing  
> > > and creating a new entry. But in any case you have to write something  
> > > somewhere when you are pulling an existing record.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Don't understand ModelForm

2009-07-21 Thread Daniel Roseman

On Jul 21, 9:34 pm, mettwoch  wrote:
> I'd like this to work:
>
> class PartnerForm(forms.ModelForm):
>     class Meta:
>         model  = Partner  # I expect that all fields are included in
> the form (the 'id' field as well)
>
> def partner_new(request):
>     form = PartnerForm()
>     return render_to_response('pos.html', {'form': form},
> RequestContext(request))
>
> def partner_edit(request):
>     form = PartnerForm(instance = request.session['partner'])
>     return render_to_response('pos.html', {'form': form},
> RequestContext(request))
>
> def partner_save(request):
>     if request.POST.get('id', None):
>         form = PartnerForm(request.POST, instance = get_object_or_404
> (Partner, pk = request.POST['id']))
>     else:
>         form = PartnerForm(request.POST)
>     if form.is_valid():
>         form.save()
>         return render_to_response('pos.html', {}, RequestContext
> (request))
>     else:
>         return render_to_response('pos.html', {'form': form},
> RequestContext(request))
>
> here's an excerpt of the pos.html:
>
>             {% if form %}
>                 
>                     
>                         {{ form.as_table }}
>                     
>                     
>                 
>             ...
>
> as I said: maybe I'm on the wrong track with ModelForm ...

Well, yes. What you've posted doesn't make any sense at all. You want
to get the id from the form, so that you can get the instance from the
database to pass to the form so it can get the id! This is obviously
circular. At some point, you've got to tell the form what the id
actually is, and that means passing it in to the page where you first
render the form. If you don't have an id, you pass a blank instance,
and a new row will be made in the database. If you do have one, pass
the instance with that id, and the existing row will be edited.

Various people have posted more or less complex code to do this, but
the simplest is like this:

def my_form_view(request, partner_id=None):
if partner_id:
partner = Partner.objects.get(id=partner_id)
else:
partner = Partner()

if request.POST:
form = PartnerForm(request.POST, instance=partner)
if form.is_valid():
form.save()
return HttpResponseRedirect('/')
else:
form = PartnerForm(instance=partner)

return render_to_response('pos.html', {'form': form},
RequestContext(request))

One final thing - make your form action="." so it posts back to the
same URL, ie the one with the partner_id.

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



Re: Don't understand ModelForm

2009-07-21 Thread mettwoch

Of course! The mistake is that I didn't have the ID in the URL, but I
took the partner to be edited somewhere from the session. I'll change
the code and it should work as expected.

Thanks again for your patience

Marc

On Jul 21, 10:57 pm, Daniel Roseman  wrote:
> On Jul 21, 9:34 pm, mettwoch  wrote:
>
>
>
> > I'd like this to work:
>
> > class PartnerForm(forms.ModelForm):
> >     class Meta:
> >         model  = Partner  # I expect that all fields are included in
> > the form (the 'id' field as well)
>
> > def partner_new(request):
> >     form = PartnerForm()
> >     return render_to_response('pos.html', {'form': form},
> > RequestContext(request))
>
> > def partner_edit(request):
> >     form = PartnerForm(instance = request.session['partner'])
> >     return render_to_response('pos.html', {'form': form},
> > RequestContext(request))
>
> > def partner_save(request):
> >     if request.POST.get('id', None):
> >         form = PartnerForm(request.POST, instance = get_object_or_404
> > (Partner, pk = request.POST['id']))
> >     else:
> >         form = PartnerForm(request.POST)
> >     if form.is_valid():
> >         form.save()
> >         return render_to_response('pos.html', {}, RequestContext
> > (request))
> >     else:
> >         return render_to_response('pos.html', {'form': form},
> > RequestContext(request))
>
> > here's an excerpt of the pos.html:
>
> >             {% if form %}
> >                 
> >                     
> >                         {{ form.as_table }}
> >                     
> >                     
> >                 
> >             ...
>
> > as I said: maybe I'm on the wrong track with ModelForm ...
>
> Well, yes. What you've posted doesn't make any sense at all. You want
> to get the id from the form, so that you can get the instance from the
> database to pass to the form so it can get the id! This is obviously
> circular. At some point, you've got to tell the form what the id
> actually is, and that means passing it in to the page where you first
> render the form. If you don't have an id, you pass a blank instance,
> and a new row will be made in the database. If you do have one, pass
> the instance with that id, and the existing row will be edited.
>
> Various people have posted more or less complex code to do this, but
> the simplest is like this:
>
> def my_form_view(request, partner_id=None):
>     if partner_id:
>         partner = Partner.objects.get(id=partner_id)
>     else:
>         partner = Partner()
>
>     if request.POST:
>         form = PartnerForm(request.POST, instance=partner)
>         if form.is_valid():
>             form.save()
>             return HttpResponseRedirect('/')
>     else:
>         form = PartnerForm(instance=partner)
>
>     return render_to_response('pos.html', {'form': form},
> RequestContext(request))
>
> One final thing - make your form action="." so it posts back to the
> same URL, ie the one with the partner_id.
>
> That's all there is to it - nothing complicated at all.
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Don't understand ModelForm

2009-07-21 Thread Dan Harris

Oh I gotcha now.

Django model forms by default do not represent auto fields (ID's)
because it wouldn't make much sense for a user to be able to edit the
PK in a form. Having said that, I do understand why you need to be
able to see the PK.

I shown in my example, I personally prefer to represent the PK in the
url so something like

http://localhost/Partner/Edit/3 would be sent to the view:

def edit(request, id):

If you do not like doing it that way, you just have to pass the ID of
the partner object into your template. SInce you are saving your
partner object in session you can get access to it right away in the
template. Just alter your template a bit:


  
   
 {{ form.as_Table}}
   
   
   

Now you ahve Id available in your post data, so you can do your check.

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



Re: Foreign Keys

2009-07-21 Thread AKK

Thank you, got it working

On 21 July, 16:55, Daniel Roseman  wrote:
> On Jul 21, 4:25 pm, AKK  wrote:
>
>
>
> > Thanks, i tried this:
>
> > blog_posts = Post.objects.filter(post_slug=slug)
> > blog_comments = blog_posts.comment_set.all()
>
> > but i got this error and i don't know why:
>
> > Traceback:
> > File "C:\ProgLangs\Python25\lib\site-packages\django\core\handlers
> > \base.py" in get_response
> >   86.                 response = callback(request, *callback_args,
> > **callback_kwargs)
> > File "C:/Program Files/Apache2.2\akonline\blog\views.py" in title_view
> >   17.     blog_comments = blog_posts.comment_set.all()
>
> > Exception Type: AttributeError at /blog/first_post/
> > Exception Value: 'QuerySet' object has no attribute 'comment_set'
>
> > Andrew
>
> You can't do it on the whole blog_posts queryset, you have to do it on
> each blog_post object within the queryset.
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



best approaches with render_to_response and large forms

2009-07-21 Thread Juan Hernandez
Hi there,

i have two questions in my mind.

1- Let's say that I have tens of views. Do I always have to use
render_to_response? I find it totally against DRY. My solution was creating
a wrapper that would take as arguments the template file name and a
dictionary with all the parameters for that template and return the
render_to_response object. is there any other approach?

2- Let's say that I have a very big form. Something like a long report that
for some weird or bureaucratic reason can't be cut into easier pieces to
fill. Is there any way where I could simply check every field for
cleaned_data['xxx'] at once instead of writing every single line? I am doing
a list and then a map() against it but I feel I'm not using the best
practice here... any thoughts?

Thanx a lot people
Juan

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



Re: Don't understand ModelForm

2009-07-21 Thread Shawn Milochik

To expand on  what Dan said with a full (tested and working) example:

In urls.py:


 (r'^partner/$', 'partner_page'),
 (r'^partner/(?P\d+)/$', 'partner_page'),


In the form tag of your template:
 


The view:

@login_required
def partner_page(request, partner_id = None):

 if partner_id:
 #existing partner
 partner_instance = get_object_or_404(partner, pk = partner_id)
 else:
 #new partner
 partner_form = partnerForm()
 partner_instance = None

 if request.POST:
 post_data = request.POST.copy()
 partner_form = partnerForm(post_data, instance =  
partner_instance)

 if partner_form.is_valid():
 the_partner = partner_form.save()
 partner_id = the_partner.id

 template_file = 'partner.html'

 context = {
 'partner_form': partner_form,
 'partner_id': partner_id,
 }

 return render_to_response(template_file, context,  
RequestContext(request))







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



Re: best approaches with render_to_response and large forms

2009-07-21 Thread Shawn Milochik

On Jul 21, 2009, at 5:21 PM, Juan Hernandez wrote:

> Hi there,
>
> i have two questions in my mind.
>
> 1- Let's say that I have tens of views. Do I always have to use  
> render_to_response? I find it totally against DRY. My solution was  
> creating a wrapper that would take as arguments the template file  
> name and a dictionary with all the parameters for that template and  
> return the render_to_response object. is there any other approach?
>
> 2- Let's say that I have a very big form. Something like a long  
> report that for some weird or bureaucratic reason can't be cut into  
> easier pieces to fill. Is there any way where I could simply check  
> every field for cleaned_data['xxx'] at once instead of writing every  
> single line? I am doing a list and then a map() against it but I  
> feel I'm not using the best practice here... any thoughts?
>
> Thanx a lot people
> Juan


#1. What do you mean -- tens of views that all populate the same  
template in the same response? If so, then you can have any number of  
functions that don't receive request objects and return response  
objects, and call them to do whatever you need. You might want to have  
a look at the RequestContext object, and the idea of putting a bunch  
of functions into one place and making use of the  
TEMPLATE_CONTEXT_PROCESSORS tuple in settings.py.

#2. Can you do something like:

 for key, value in cleaned_data.items():
 if value:
 pass #do something
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: What editor do you use for .po files?

2009-07-21 Thread Jonas Obrist

Haven't started by i18n yet but rosetta looks good: 
http://code.google.com/p/django-rosetta/

bittin wrote:
> i also use PoEdit =)
>
> On Fri, Jun 19, 2009 at 11:05 PM, Joshua Russo 
> mailto:joshua.rupp...@gmail.com>> wrote:
>
>
> I started using PoEdit but it seems to thing that the .po files
> created by makemessages are malformed, or at least don't have all the
> right headers. Is there a better editor for Windows?
>
> i
>
> >


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



OR in query_set

2009-07-21 Thread caliman

How do you use django to use OR instead av AND when you use filter?

Let's say I want:
SELECT * FROM table WHERE attrib1 IN (1,2,3)  OR attrib2 IN (4,5,6)

in django:
table.objects.filter(attrib1__in=[1,2,3]).filter(attrib2__in=[4,5,6])

this will be like:
SELECT * FROM table WHERE attrib1 IN (1,2,3)  AND attrib2 IN (4,5,6)

I want:
table.objects.filter(attrib1__in=[1,2,3] OR attrib2__in=[4,5,6])
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: OR in query_set

2009-07-21 Thread Alex Gaynor

On Tue, Jul 21, 2009 at 4:48 PM, caliman wrote:
>
> How do you use django to use OR instead av AND when you use filter?
>
> Let's say I want:
> SELECT * FROM table WHERE attrib1 IN (1,2,3)  OR attrib2 IN (4,5,6)
>
> in django:
> table.objects.filter(attrib1__in=[1,2,3]).filter(attrib2__in=[4,5,6])
>
> this will be like:
> SELECT * FROM table WHERE attrib1 IN (1,2,3)  AND attrib2 IN (4,5,6)
>
> I want:
> table.objects.filter(attrib1__in=[1,2,3] OR attrib2__in=[4,5,6])
> >
>

You can use Q objects to do OR queries.

http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me

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



Bug when creating Q object from string representation of another Q object?

2009-07-21 Thread Margie

I have a situation where I want to do the following:
   take a bunch of POST params and from them create a Q object
   urlencode that Q object and turn it into a GET param, redirect
using that param
   process the GET that contains the urlencoded Q object, create a
Q object from it, and use it in a filter


I think this should all be possible, however, I am having trouble
recreating the new Q object from the string representation of the
original Q object. Here's an example of the problem:

>>> filter_orig = Q(owner__username='mlevine')
>>> print filter_orig
(AND: ('owner__username', 'mlevine'))
>>> filter_new = Q("%s" % orig)
>>> print filter_new
(AND: (AND: ('owner__username', 'mlevine')))
>>> Task.objects.filter(filter_orig)
[, ]
>>> Task.objects.filter(filter_new)
Traceback (most recent call last):
...
  File "/home/mlevine/django/django_libs/django-admin-ui-july8/lib/
python2.6/site-packages/django/db/models/sql/query.py", line 1520, in
add_filter
arg, value = filter_expr


Note that in the above log, when I print filter_new, there is an extra
AND at the front.  Logically this shouldn't be be a problem, but I
suspect that it is indicative of the problem.

Is what I'm doing above supposed to work?  Is this a bug?

This is using 1.1 beta.

Margie



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



Re: OR in query_set

2009-07-21 Thread Stefan Hjelm

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



replicating database changes from one postgres DB to another

2009-07-21 Thread Steve Howell

We have an application where we periodically import data from an
external vendor, and the process is mostly automated, but we need to
review the data before having it go live.

We were considering an option where we would run processes on another
database, do the manual validation, and then replicate the DB changes
to our production database (which would have the same schema).

One option is to do it all through postgres, but I am thinking there
may be advantages in doing it through django, just in the sense that
it might be easier to script and/or add intelligence to the
replication as needed.

Is there anything in django that would facilitate this?  If not, my
slightly off-topic question would be how best to do this in postgres.
Essentially, we want some process to generate a log of DB inserts/
updates/deletes on the one side and replay it on the other.

Thanks,

Steve

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



Re: replicating database changes from one postgres DB to another

2009-07-21 Thread Wayne Koorts

Hi Steve,

> We have an application where we periodically import data from an
> external vendor, and the process is mostly automated, but we need to
> review the data before having it go live.
>
> We were considering an option where we would run processes on another
> database, do the manual validation, and then replicate the DB changes
> to our production database (which would have the same schema).

I do exactly this with one of my sites.  This is my scenario:

1.  Main database table gets updated automatically every night (this
is a kind of data that can be automatically refreshed, but that should
be beside the point for this discussion).  The data first goes into a
pending table on my dev server, which is exactly the same as the main
table, with "_pending" appended to the name.
2.  The data is then dumped to a file using "psql" and sent via FTP up
to an equivalent pending table on the production server (via Python
script in my dev environment).  There is a Python script set up on the
server to monitor a specific folder for a specific dump file name at
regular intervals, and if it finds it, imports it into the table also
with "psql", then deletes the dump file.
3.  The data sits in the pending table on the production server until
I approve it via an admin interface which I have set up Django.
Basically there is a "DB Admin" area on the site which I have set up
which shows me four chunks of the data at various points in the table,
100 at the start, 100 at 1/4 through, 100 at 3/4 through and then 100
at the end.  It also shows me the total number of records so that I
can do a quick visual integrity check.
4.  There are "approve" and "reject" buttons at the bottom of the
approval page.  If I click "approve" it moves the current live table
data into a backup table (the db admin area also has a restore
function) and moves the pending data into the live table using a raw
nested SQL SELECT statement via Django and then empties the pending
table.  If I click "reject" it just empties the pending table.

These same general steps can be adjusted to accomodate more tables
etc. as per your requirements.

Hope this helps,

Regards,
Wayne Koorts
http://www.wkoorts.com
http://www.blazingpanther.com

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



How to design a new website? (about apps)

2009-07-21 Thread Léon Dignòn

Ok, I have finished the tutorials and learned a lot about Django. I
created a polls application and tuned the admin site, etc.

Now I want to continue in a bigger application. After some successful
coding I ran into a big problem not covered by any piece of
documentation out there:

1. Do I need apps and
2. when to create them?


I plan to create a site where users can basically upload specific
images, rate images of other users and -if they like - to download
them. Any user should have a profile with additional information.
Images are categorized and users can browse them and filter them.
Maybe in future other functions like a forum or stuff will follow.

Well, the forum is, just like the poll, an application, because it is
not a basic function but a separate and autonomous function. But the
additional user information and the upload form and the image browser
are basic functions which interact with each other little more than
poll and forum.

I am highly confused …

These questions I would love to see answered:
- Do I create an app for the additional user information, or do I
create a model.py in the site root because it's a main functionality?
- Do I create an app for the image upload and browser, or do I create
a model.py in the site root because it's a main functionality?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to design a new website? (about apps)

2009-07-21 Thread Javier Guerra

On Tue, Jul 21, 2009 at 10:19 PM, Léon Dignòn wrote:
> These questions I would love to see answered:
> - Do I create an app for the additional user information, or do I
> create a model.py in the site root because it's a main functionality?
> - Do I create an app for the image upload and browser, or do I create
> a model.py in the site root because it's a main functionality?

if in doubt, do a separate app.  each app should handle one specific
job. if it doesn't go in the same sentence, it's a different app.

check the djangoCon videos on youtube, there's a lot of insights on
this (don't remember who gave that talk, and i can't access youtube
from work)

-- 
Javier

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



Re: MEDIA_ROOT and file uploads

2009-07-21 Thread J

It worked automatically for me.


Make sure you put enctype="multipart/form-data" in the form definition

http://docs.djangoproject.com/en/dev/topics/http/file-uploads/

Note that request.FILES will only contain data if the request method was
POST and the  that posted the request has the attribute
enctype="multipart/form-data". Otherwise, request.FILES will be empty.




Léon Dignòn wrote:
> Hello everybody,
>
> I created an upload form with the help of the docs.
> http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#topics-http-file-uploads
>
> But the handle_uploaded_file() bugs me a little bit. I set MEDIA_ROOT
> (MR) in the settings.py to an existing directory. I thought that file
> uploads work together with MR but in the docs the file is saved
> "manually" on the disk. Is there no django method which saves the file
> automatically with a given name on the disk?
>
> The result should be something like this:
> (with the file saved at MEDIA_ROOT/myfile.jpg):
>
> def def handle_uploaded_file(f):
> f.save("myfile.jpg")
>
> Instead of:
>
> def handle_uploaded_file(f):
> destination = open('some/file/name.txt', 'wb+')
> for chunk in f.chunks():
> destination.write(chunk)
> destination.close()
>
> >
>
>   


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



Re: How to design a new website? (about apps)

2009-07-21 Thread Léon Dignòn

I found it, it's really really great!!
http://www.youtube.com/watch?v=A-S0tqpPga4

On Jul 22, 12:30 am, Javier Guerra  wrote:
> On Tue, Jul 21, 2009 at 10:19 PM, Léon Dignòn wrote:
> > These questions I would love to see answered:
> > - Do I create an app for the additional user information, or do I
> > create a model.py in the site root because it's a main functionality?
> > - Do I create an app for the image upload and browser, or do I create
> > a model.py in the site root because it's a main functionality?
>
> if in doubt, do a separate app.  each app should handle one specific
> job. if it doesn't go in the same sentence, it's a different app.
>
> check the djangoCon videos on youtube, there's a lot of insights on
> this (don't remember who gave that talk, and i can't access youtube
> from work)
>
> --
> Javier
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Strange things happening with reverse url lookups

2009-07-21 Thread Vasil Vangelovski

I've posted a question about this a few days ago and I thought I was
confused about something, but it was probably some problem with the
django revision at the time or I'm even more confused now. So... I
have an application called epg with a model named Show and I want to
provide a link for editing an instance of this model on the admin.
Now, the django checkout on my laptop is a week old and the one on my
desktop was updated today, so this code:

reverse('admin_epg_Show_change', args = (id,))

works on my laptop but does not work on my desktop

and this code:

reverse('admin:epg_Show_change', args = (id,))

works on my desktop but doesn't work on my laptop

what's going on??? which one should I use??? What will stick in django
1.1 final??? Judging by the docs for the admin it should be the second
one, but I'm confused.

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



Re: Strange things happening with reverse url lookups

2009-07-21 Thread Michael
On Tue, Jul 21, 2009 at 7:53 PM, Vasil Vangelovski
wrote:

>
> I've posted a question about this a few days ago and I thought I was
> confused about something, but it was probably some problem with the
> django revision at the time or I'm even more confused now. So... I
> have an application called epg with a model named Show and I want to
> provide a link for editing an instance of this model on the admin.
> Now, the django checkout on my laptop is a week old and the one on my
> desktop was updated today, so this code:
>
> reverse('admin_epg_Show_change', args = (id,))
>
> works on my laptop but does not work on my desktop
>
> and this code:
>
> reverse('admin:epg_Show_change', args = (id,))
>
> works on my desktop but doesn't work on my laptop
>
> what's going on??? which one should I use??? What will stick in django
> 1.1 final??? Judging by the docs for the admin it should be the second
> one, but I'm confused.
>

The second version JUST was implemented less then a week ago. It will ship
in the 1.1 final. Try updating your svn copy on the the laptop, it should
work as well.

Hope that helps,

Michael

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



Re: Strange things happening with reverse url lookups

2009-07-21 Thread Karen Tracey
On Tue, Jul 21, 2009 at 7:53 PM, Vasil Vangelovski
wrote:

>
> I've posted a question about this a few days ago and I thought I was
> confused about something, but it was probably some problem with the
> django revision at the time or I'm even more confused now. So... I
> have an application called epg with a model named Show and I want to
> provide a link for editing an instance of this model on the admin.
> Now, the django checkout on my laptop is a week old and the one on my
> desktop was updated today, so this code:
>
> reverse('admin_epg_Show_change', args = (id,))
>
> works on my laptop but does not work on my desktop
>
> and this code:
>
> reverse('admin:epg_Show_change', args = (id,))
>
> works on my desktop but doesn't work on my laptop
>
> what's going on??? which one should I use??? What will stick in django
> 1.1 final??? Judging by the docs for the admin it should be the second
> one, but I'm confused.
>

Sounds like you have one machine with a checkout from before:

http://code.djangoproject.com/changeset/11250

and one after.  The "after" is what will be in 1.1, as the ticket fixed by
that changeset was the last big blocker for 1.1

Karen

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



Re: UnicodeEncodeError on admin site

2009-07-21 Thread Rodrigo Gomes
Hi Daniel,

I just changed my method as you suggested, to def __unicode__(self) and the
problem was solved.

Thanks so much!
Rodrigo

On Tue, Jul 21, 2009 at 12:54 PM, Daniel Roseman wrote:

>
> On Jul 21, 3:46 pm, Rodrigo Gomes  wrote:
> > Hi Daniel,
> >
> > My databse enconding (Mysql) is utf-8, as you can see below:
> >
> > Server characterset:latin1
> > Db characterset:utf8
> > Client characterset:latin1
> > Conn.  characterset:latin1
>
> But what about your actual tables? When you do 'SHOW CREATE TABLE
> mytablename;', what does it show for the DEFAULT CHARSET value at the
> end?
>
> > There is something strange, because I'm showing the same information on
> my
> > page and I'm not getting that error that I showed before.
> >
> > The difference is that in my page I put  > content="text/html; charset=utf-8" /> (without this I get the error)
> >
> > My model code It's just mapping the database fields to python code, just
> > like this:
> > (the class and variable names are in Portuguese)
> >
> > Is it missing something?
> >
> > *from django.db import models
> >
> > class PresenteRecebido(models.Model):
> > nome_convidado = models.CharField(max_length=60)
> > data_recebimento = models.DateField()
> > email = models.EmailField()
> > descricao_presente = models.CharField(max_length=300)
> > ip = models.CharField(max_length=100)
> >
> > def __str__(self):
> > return self.nome_convidado + " - " + self.descricao_presente*
>
> Probably not the cause of the problem but you shouldn't be using
> __str__, you should be using __unicode__. And you should make sure it
> actually returns unicode:
>
> def __unicode__(self):
>return u'%s - %s' % (self.nome_convidado, self.descricao_presente)
>
> --
> DR.
> >
>

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



Re: Strange things happening with reverse url lookups

2009-07-21 Thread Vasil Vangelovski

Thanx

It was just my luck reading about this new feature in the URL
dispatcher and trying to use it in my project moments before it was
added to trunk :)

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



Django 1.1 release candidate now available

2009-07-21 Thread James Bennett

Hi folks! Tonight we've pushed out the Django 1.1 release candidate,
which is hopefully the last stepping-stone to the final 1.1 release.
If you'd like to try it out, here's where you'll want to look:

* Download instructions: http://www.djangoproject.com/download/
* Release notes: http://docs.djangoproject.com/en/dev/releases/1.1-rc-1/
* Blog post announcing the release:
http://www.djangoproject.com/weblog/2009/jul/21/rc/

If all goes well, we'll see you back here in one week's time for the
final 1.1 release.


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



Re: Django 1.1 release candidate now available

2009-07-21 Thread Joshua Partogi
Congrats! Thanks to everyone that have put all their effort delivering this
beautiful framework.

Regards,

On Wed, Jul 22, 2009 at 12:35 PM, James Bennett wrote:

>
> Hi folks! Tonight we've pushed out the Django 1.1 release candidate,
> which is hopefully the last stepping-stone to the final 1.1 release.
> If you'd like to try it out, here's where you'll want to look:
>
> * Download instructions: http://www.djangoproject.com/download/
> * Release notes: http://docs.djangoproject.com/en/dev/releases/1.1-rc-1/
> * Blog post announcing the release:
> http://www.djangoproject.com/weblog/2009/jul/21/rc/
>
> If all goes well, we'll see you back here in one week's time for the
> final 1.1 release.
>
>
-- 
http://blog.scrum8.com
http://twitter.com/scrum8

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



Re: Windows development server problem

2009-07-21 Thread cwurld

Hi,

Sorry for not giving more details. I did not want to get into my code
as much as I was hoping to find out more about how the dev server
might differ from the command line.

I was using the pod module (http://code.google.com/p/pickled-object-
database/) in addition to mysql.

It turns out that the reason the code would not work in the dev server
was based differences in the way import statements function in the dev
server. When I imported the my pod database models using the command
line each class ended up with a names like models.AModel. But when I
imported them using the dev server they ended up with names like
myproject.models.AModel. Since pod derives info from the class name,
it failed in one case and worked in the other.

I should note that pod is still in development. I think the way info
is derived from class names will need to be changed.

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



Re: django profiles :: choices form?

2009-07-21 Thread Saketh
Thanks, Léon -- this was exactly what I was looking for!

Sincerely,
Saketh


On Tue, Jul 21, 2009 at 6:37 AM, Léon Dignòn  wrote:

>
> You might take a look at this:
> http://docs.djangoproject.com/en/dev/ref/models/fields/#ref-models-fields
>
> models.py
> 
> class Foo(models.Model):
>GENDER_CHOICES = (
>('M', 'Male'),
>('F', 'Female'),
>)
>gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
>
>
> On Jul 20, 11:24 pm, Saketh  wrote:
> > Hi everyone,
> >
> > I am making a user settings page for my application based on django-
> > registration and django-profiles, but I'm running into a small problem
> > in how I'd like the page to be laid out.
> >
> > My data model has a field that can take on only three values, 'A',
> > 'B', and 'C'. I have modeled this as a CharField with max_length=1.
> > I'd like the generated form in the edit_profile view to be a list box
> > with only those three options, rather than an actual character field,
> > but I'm not able to figure out how to do this -- the closest thing
> > I've found so far is here:
> http://birdhouse.org/blog/2009/06/27/django-profiles/.
> >
> > Is there a way that I can use the list box to work with the three-
> > valued field? Also, is there a more natural way to represent the
> > finitely-valued field in the model itself?
> >
> > Thanks!
> >
> > -Saketh
> >
>

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



  1   2   >