Re: Decimal * Float problem

2011-05-11 Thread Colin Corbett
Thanks!  Solved:

In models.py:

class OurProducts(models.Model):
  code = models.CharField(max_length=60)
  name = models.CharField(max_length=80)
  price = models.DecimalField (max_digits=8, decimal_places=2)

  def combined_price(self):
from decimal import Decimal
return round(self.price * Decimal(0.65),2)




On May 10, 9:41 pm, Shawn Milochik  wrote:
> What error do you get?
>
> You should be able to import Decimal then do: discount = Decimal('0.65')

-- 
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: performance of model instgance save()

2011-05-11 Thread Daniel Roseman
On Wednesday, May 11, 2011 7:50:16 AM UTC+1, Brian wrote:
>
> Sure - it's just that bit more convenient and readable to use the ORM 
> approach. If I get the chance, I must try substituting direct calls to 
> psycopg and see if that makes it significantly faster again. I'd guess 
> there's maybe another factor of 2 to be had.


I'd think you'll find it's significantly more than a factor of 2. For bulk 
inserts, raw SQL is often several orders of magnitude faster.
--
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.



My DEF is not displaying on the Admin Form??

2011-05-11 Thread Colin Corbett
Hello,

My DEF is not displaying on the Admin Form.

models.py =

class OurProducts(models.Model):
  code = models.CharField(max_length=60)
  price = models.DecimalField (max_digits=8, decimal_places=2)

  def combined_price(self):
from decimal import Decimal
return round(self.price * Decimal(0.65),2)


admin.py =

class OurProductsAdmin(admin.ModelAdmin):
readonly_fields= ('combined_name',)
fieldsets = [
(None,   {'fields': ['code', 'price',
'combined_price']}),
]
list_display = ('combined_price' ,'code', 'price')


The 'combined_price' show fine in my list_display, but the
'combined_price' does not show in the admin.form.

Thanks for any help!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: performance of model instgance save()

2011-05-11 Thread Thomas Weholt
On Wed, May 11, 2011 at 10:21 AM, Daniel Roseman  wrote:
> On Wednesday, May 11, 2011 7:50:16 AM UTC+1, Brian wrote:
>>
>> Sure - it's just that bit more convenient and readable to use the ORM
>> approach. If I get the chance, I must try substituting direct calls to
>> psycopg and see if that makes it significantly faster again. I'd guess
>> there's maybe another factor of 2 to be had.
>
> I'd think you'll find it's significantly more than a factor of 2. For bulk
> inserts, raw SQL is often several orders of magnitude faster.


You might want to check out http://pypi.python.org/pypi/dse/. My tests
using postgres showed a 3X performance gain on inserts compared to
using the orm and nearly 10X when doing heavy updates on existing
data. It takes care of creating SQL for you and respects default
values defined in your models.

Thomas

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



Filtering on weekday

2011-05-11 Thread Benedict Verheyen
Hi,


I've developed a calltracking app and I would want to know how many calls we 
have
on Monday, Tuesday and so on.
I would like to filter on weekdays as specified in the date module as 
date.weekday()
Is there an easy way to do this?
I've tried this:

c=Call.objects.filter(date_created__day=3)

But it's not correct as this displays all calls made on any 3rd of the month 
instead
of the 3rd of the week.

Thanks,
Benedict

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



EuroPython: Early Bird will end in 2 days!

2011-05-11 Thread Palla
Hi all,

If you plan to attend, you could save quite a bit on registration fees!

The end of Early bird is on May 12th, Friday, 23:59:59 CEST. We'd like
to ask to you to forward this post to anyone that you feel may be
interested.

We have an amazing lineup of tutorials, events and talks. We have some
excellent keynote speakers and a very complete partner program... but
early bird registration ends in 2 days!

Right now, you still get discounts on talks and tutorials so if you
plan to attend Register Now:

http://ep2011.europython.eu/registration/

While you are booking, remember to have a look at the partner program
and our offer for a prepaid, data+voice+tethering SIM.

All the best,

-- 
->PALLA

-- 
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: [] Filtering on weekday

2011-05-11 Thread Henrik Genssen
you should try week_day instead
http://docs.djangoproject.com/en/dev/ref/models/querysets/#week-day

regards
Henrik

>reply to message:
>date: 11.05.2011 11:38:40
>from: "Benedict Verheyen" 
>to: django-users@googlegroups.com
>subject: [] Filtering on weekday
>
>Hi,
>
>
>I've developed a calltracking app and I would want to know how many calls we 
>have
>on Monday, Tuesday and so on.
>I would like to filter on weekdays as specified in the date module as 
>date.weekday()
>Is there an easy way to do this?
>I've tried this:
>
>c=Call.objects.filter(date_created__day=3)
>
>But it's not correct as this displays all calls made on any 3rd of the month 
>instead
>of the 3rd of the week.
>
>Thanks,
>Benedict
>
>-- 
>You received this message because you are subscribed to the Google Groups 
>"Django users" group.
>To post to this group, send email to django-users@googlegroups.com.
>To unsubscribe from this group, send email to 
>django-users+unsubscr...@googlegroups.com.
>For more options, visit this group at 
>http://groups.google.com/group/django-users?hl=en.
>

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



Re: [] Filtering on weekday

2011-05-11 Thread Benedict Verheyen
On 11/05/2011 11:47, Henrik Genssen wrote:
> you should try week_day instead
> http://docs.djangoproject.com/en/dev/ref/models/querysets/#week-day
> 
> regards
> Henrik

Henrik,

thanks, it works. I don't know how I missed that.

Regards,
Benedict


-- 
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: unit testing and file location

2011-05-11 Thread Calvin Spealman
You can run your tests with their own --settings parameter with the specific
variations you want to test under.

On May 10, 2011 5:21 PM, "Brian Craft"  wrote:

I would like unit tests that do file manipulations to run with a
different storage "location", so they're not manipulating real app
files. Is there a good way to do this? Is there a way to override
model field initializers, so I can instance a model, passing in the
'storage' parameter for an ImageField in the model?

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

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



form that displays an elements list with checkboxes

2011-05-11 Thread Marc Aymerich
Hi,
I want to do a form that displays a list of elements that can be selected
with a checkbox and then submit the selected elements, but I haven't found
any code sample for this. I'll apreciate if someone can give me a link to an
example or any advice on this!

Many thanks!
-- 
Marc

-- 
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: form that displays an elements list with checkboxes

2011-05-11 Thread Daniel Roseman
On Wednesday, May 11, 2011 2:17:07 PM UTC+1, Marc Aymerich wrote:
>
> Hi, 
> I want to do a form that displays a list of elements that can be selected 
> with a checkbox and then submit the selected elements, but I haven't found 
> any code sample for this. I'll apreciate if someone can give me a link to an 
> example or any advice on this!
>
> Many thanks!
> -- 
> Marc
>

http://docs.djangoproject.com/en/1.3/ref/forms/widgets/#django.forms.CheckboxSelectMultiple
 

-- 
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: form that displays an elements list with checkboxes

2011-05-11 Thread Marc Aymerich
On Wed, May 11, 2011 at 3:24 PM, Daniel Roseman wrote:

> On Wednesday, May 11, 2011 2:17:07 PM UTC+1, Marc Aymerich wrote:
>>
>> Hi,
>> I want to do a form that displays a list of elements that can be selected
>> with a checkbox and then submit the selected elements, but I haven't found
>> any code sample for this. I'll apreciate if someone can give me a link to an
>> example or any advice on this!
>>
>> Many thanks!
>> --
>> Marc
>>
>
>
> http://docs.djangoproject.com/en/1.3/ref/forms/widgets/#django.forms.CheckboxSelectMultiple
>


many thanks daniel :)


-- 
Marc

-- 
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: Logging view exceptions: A tip and a question.

2011-05-11 Thread Venkatraman S
On Tue, May 10, 2011 at 11:42 PM, Shawn Milochik  wrote:

>
> Assuming performance won't be a major concern, I'd like to decorate all my
> views automatically. My first thought was middleware, but since it handles
> requests and responses, I don't think it's the right layer. Does anyone know
> the best place for automatically decorating all views with a specific
> decorator?
>

My response is more along the lines of performance gain - why not use
asynchronous logging? I havent used logging extensively, but is the default
logging scheme in scheme synchronous?

-V

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



Re: Logging view exceptions: A tip and a question.

2011-05-11 Thread Shawn Milochik

On 05/11/2011 09:57 AM, Venkatraman S wrote:


My response is more along the lines of performance gain - why not use 
asynchronous logging? I havent used logging extensively, but is the 
default logging scheme in scheme synchronous?


-V


This was already answered by a couple of people yesterday -- a clean 
easy solution is to use the process_exception middleware. I don't see 
any reason to get fancy with asynchronous processing. Threads are messy 
and Celery (which I use) wouldn't be a performance gain since I'd still 
have to make a synchronous call to put it in the queue which probably 
takes longer than a logging call.


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: Decimal * Float problem

2011-05-11 Thread Ian Clelland
On Wed, May 11, 2011 at 1:14 AM, Colin Corbett wrote:

> Thanks!  Solved:
>
> In models.py:
>
> class OurProducts(models.Model):
>  code = models.CharField(max_length=60)
>  name = models.CharField(max_length=80)
>  price = models.DecimalField (max_digits=8, decimal_places=2)
>
>  def combined_price(self):
>from decimal import Decimal
>return round(self.price * Decimal(0.65),2)
>

For the sake of anyone searching the group for this issue in the future,
that last method should be:


>  def combined_price(self):

>from decimal import Decimal
   return (self.price * Decimal('0.65')).quantize(Decimal('0.01'))

Python will sensibly throw an exception if you try to create a Decimal from
a float directly, so Decimal(0.65) will not work. Also, the round() function
will turn your carefully calculated decimal value *back* into a float; you
should use .quantize() instead.

-- 
Regards,
Ian Clelland


-- 
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 use django-taggit in admin.py?

2011-05-11 Thread Thomas Weholt
I want to show tags used in a model in my admin.py file, to be able to
sort by tag etc. but it crashes with "Caught AttributeError while
rendering: 'TaggableManager' object has no attribute 'flatchoices'" if
I add 'tags' to list_filter in my ModelAdmin.

How can I use django-taggit in the admin related to my model?
-- 
Mvh/Best regards,
Thomas Weholt
http://www.weholt.org

-- 
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 get the test runner to only rebuild & populate the test_database if it changed?

2011-05-11 Thread Phlip
Djangoists:

Me again. Still helping clients TDD despite obese databases.

Right now the test suite takes a minute to build a database with >20
models (and lots of fields in each one), then load a mere 7,000
records. Yes I will cut down on the records, but building the
database, in sqlite3 :memory: mode, is also a big chunk.

So if I built the DB once, then ran a TDD cycle, couldn't the entire
system leave the database in a sqlite3 document, and put transactions
around each test case?

I'm going to copy the TestCase classes into our project, and have my
way with them. But is there an easier way, or has someone already done
this?

(1.2, BTW - the obese database prevents an upgrade to Django 1.3!)

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand

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



Readonly fields for existing items on admin inlines

2011-05-11 Thread Vinicius Massuchetto
Hi!

In a tabular inline, i want that the added items can't be changed or
deleted. I'm ok with the `can_delete` option, but setting
`readonly_fields` will also turn the form entry at the bottom to be
readonly too. There's another problem with some more fields that I
need to display in this form, like the user that added the entry. I
got something like this until now:

# models.py
class AbstractModel(models.Model):
user = models.ForeignKey(User, editable = False)
   ... some more fields ...
class Meta:
abstract = True

class ParentModel(AbstractModel):
... fields ...
class ChildModel(AbstractModel):
parent = models.ForeignKey(ParentModel, ... options ...)
... fields ...

# admin.py
class ChildModelInline(admin.TabularInline):
model = ChildModel
form = ChildModelForm
can_delete = False

class ParentModelAdmin(admin.ModelAdmin):
... options ...
inlines = (ChildModelInline,)

# forms.py
class ChildModelForm(models.ModelForm):
user = forms.CharField(required = False)
... some more fields and stuff needed ...

def __init__(self, *args, **kwargs):
super(ChildModelForm, self).__init__(*args, **kwargs)
try: user = User.objects.get(id = self.instance.user_id)
except: return None
self.fields['user'].initial = user.first_name
self.fields['user'].widget.attrs['readonly'] = 'readonly'

In this example I'm doing like I wanted the `user` field as readonly.

In the last line, If I change the widget attribute to ['disabled'] =
True, it works fine, but I need a text entry, not a disabled form
field. I'm also aware that I'll need to override the `save_model()`
and `save_formsets()` for this to work properly.

Many thanks.
-- 
Vinicius Massuchetto
http://vinicius.soylocoporti.org.br

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



Formsets and new 1.3 class based views

2011-05-11 Thread DK
What is a proper way to handle formsets with new class based views?
Should I use standard forms views like CreateView, I did not saw any
views dedicated to handle formsets.

-- 
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: Formsets and new 1.3 class based views

2011-05-11 Thread Iván Raskovsky
On Wed, May 11, 2011 at 1:29 PM, DK  wrote:
> What is a proper way to handle formsets with new class based views?
> Should I use standard forms views like CreateView, I did not saw any
> views dedicated to handle formsets.

Hi DK. I've faced the same issue some weeks ago, and I decided to make
my own CBV to handle formsets, modelformsets and inlines :)

I haven't released them yet, cause I haven't had the proper time to
document them, but the code is full of docstrings and commentaries and
I'm using them in production. You can find them in my github repo[0].

I think you'll find them easy enough to understand, but if you have
any doubts you can query me on #django or email me. Of course any
issue report or pull request is more than welcome!
Iván

[0] https://github.com/rasca/django-enhanced-cbv

-- 
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 Admin site and password field

2011-05-11 Thread Gabe
Hi all,

this is my first post on this group so be gentle ;)

I`ve crated a model class and an admin site. My model Users has
password field. How can I rewrite it to be a password field and to get
stars when I`am typing password (when creating a new user by admin
site)?

Sorry for my English but it is not my native language.

Thx for any suggestions in advance.

Gabe

-- 
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 site and password field

2011-05-11 Thread Shawn Milochik
It sounds like you're not using the built-in Django admin, which would 
make your life easier.


Assuming you want to do it the hard way, you can just use a 
PasswordInput widget.

http://docs.djangoproject.com/en/1.3/ref/forms/widgets/


--
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: Formsets and new 1.3 class based views

2011-05-11 Thread DK
Fantastic piece of work. I will try to dive into.
DK

On May 11, 8:02 pm, Iván Raskovsky  wrote:
> On Wed, May 11, 2011 at 1:29 PM, DK  wrote:
> > What is a proper way to handle formsets with new class based views?
> > Should I use standard forms views like CreateView, I did not saw any
> > views dedicated to handle formsets.
>
> Hi DK. I've faced the same issue some weeks ago, and I decided to make
> my own CBV to handle formsets, modelformsets and inlines :)
>
> I haven't released them yet, cause I haven't had the proper time to
> document them, but the code is full of docstrings and commentaries and
> I'm using them in production. You can find them in my github repo[0].
>
> I think you'll find them easy enough to understand, but if you have
> any doubts you can query me on #django or email me. Of course any
> issue report or pull request is more than welcome!
>     Iván
>
> [0]https://github.com/rasca/django-enhanced-cbv

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



DecimalFields, Floats, and Strings?

2011-05-11 Thread Nan
Using Django 1.2.3, I recently declared a DecimalField on a model, and
it happily accepts a float as its default value, but it won't filter
on a float (it throws a TypeError instead).  Is there a reason for
this inconsistency?

-- 
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: DecimalFields, Floats, and Strings?

2011-05-11 Thread Shawn Milochik

On 05/11/2011 03:01 PM, Nan wrote:

Using Django 1.2.3, I recently declared a DecimalField on a model, and
it happily accepts a float as its default value, but it won't filter
on a float (it throws a TypeError instead).  Is there a reason for
this inconsistency?



DecimalField subclasses Field, which forces the return value into 
unicode before returning it. This would explain why it accepts a default 
value of a float, but it's still technically incorrect to provide a 
float as a default value for a DecimalField.


It is impossible to use a floating-point number to look up a Decimal, 
just because it is. That's why you can't look it up.


It does look like a bit of a discrepancy, but the answer is that you 
should never be using floats with Decimal or DecimalField objects 
anyway. Even if it appears to work, there's always a very real chance 
that you think you're putting into your database isn't actually what 
you're putting into your database. Either pass a Decimal object or a 
string as the default value to your DecimalField.


Shawn


http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/__init__.py

--
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: Formsets and new 1.3 class based views

2011-05-11 Thread Iván Raskovsky
BTW you can find some example views and how to use them in the tests!
Iván

On Wed, May 11, 2011 at 3:50 PM, DK  wrote:
> Fantastic piece of work. I will try to dive into.
> DK
>
> On May 11, 8:02 pm, Iván Raskovsky  wrote:
>> On Wed, May 11, 2011 at 1:29 PM, DK  wrote:
>> > What is a proper way to handle formsets with new class based views?
>> > Should I use standard forms views like CreateView, I did not saw any
>> > views dedicated to handle formsets.
>>
>> Hi DK. I've faced the same issue some weeks ago, and I decided to make
>> my own CBV to handle formsets, modelformsets and inlines :)
>>
>> I haven't released them yet, cause I haven't had the proper time to
>> document them, but the code is full of docstrings and commentaries and
>> I'm using them in production. You can find them in my github repo[0].
>>
>> I think you'll find them easy enough to understand, but if you have
>> any doubts you can query me on #django or email me. Of course any
>> issue report or pull request is more than welcome!
>>     Iván
>>
>> [0]https://github.com/rasca/django-enhanced-cbv
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Problems using django-taggit; tags disappear in the admin

2011-05-11 Thread Thomas Weholt
I got a model using django-taggit. It works great when I add tags in
the admin, but when the tags are added in code ( they're read from the
EXIF-data in a photo, the keywords part ) - nothing is shown in the
admin change form tag-field for the model. I can see the values are
stored correctly when I debug the save-method, but when the model
instance is shown in the admin the tag-field is empty.

>>> from photoapp.models import *
>>> d = AdvancedPhoto(title='1', image='/home/thomas/Pictures/test.jpg')
>>> d.save()
>>> d.tags.all()
[, , ]
>>> AdvancedPhoto.objects.all()[1].tags.all()
[, , ]

This works fine. Saving/adding a photo in the admin and then checking
it in the shell afterwards:
>>> from photoapp.models import *
>>> AdvancedPhoto.objects.all()[0].tags.all()
[]

Hmmm ... what's going on??


-- 
Mvh/Best regards,
Thomas Weholt
http://www.weholt.org

-- 
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-profile redirect to user's profile

2011-05-11 Thread christian.posta
I'm trying to understand the best way to redirect a user to their
profile once they successfully login to the application.

I'm using django-profiles to manage a custom user profile. By default,
the redirect url is specified in settings.py as LOGIN_REDIRECT_URL.
However, the url entry in the django-profiles app is looking for a url
pattern such as this: /profile/. How can I redirect to that
type of URL after a successful login? I guess the answer to that
immediate question is simple, but couple my question with the fact
that I'm using the pinax account app that handles the logging in. I
can set the 'success_url' but I cannot set the  parameter to
the profiles url when doing that. I guess the hard dependency in my
question is the pinax account application. How do other's tie together
their account+profile apps? Do they rely on and build around the
django contrib account implementation? and couple with django-
profiles?

Any discussion around this topic would be most helpful.
Thanks,
Christian

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



imagefield upload_to

2011-05-11 Thread Brian Craft
I have a model with an imagefield, and some fields that are computed
from the image. I'm trying to override the "save" method to fill in
the other fields.

When I test this in the admin, there are two problems: first, the path
(mymodel.image.path) doesn't honor the upload_to setting on the field.
It concats MEDIA_ROOT and the file name, w/o the upload_to. (This is
django 1.2.3). Second, I don't see the file in the filesystem when
.save() is called. Perhaps save() is the wrong place to do this?

If I don't try to generated the computed fields, the file is created
in the correct (upload_to) directory, and if I read the object from
the db, mymodel.image.path is also correct.

Looks like upload_to is only accessed during FieldFile.save(), where
the self.name is updated, so the path is always wrong before that.

And apparently the file isn't committed to storage until the field is
saved. Is there some other way to access the file before it is saved?

-- 
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: Error (EXTERNAL IP): /add_comment/10/

2011-05-11 Thread Aragorn
Thanks  !!!
Now it works great!

On 10 Mag, 00:29, Ulrich Petri  wrote:
> > message = "Comment was was added to '%s' by '%s': \n\n%s" % (self.post, 
> > self.author, self.body)
>
> Most likely your users are posting utf-8 data which you are trying to insert 
> into a byte string .
>
> To fix this change that line to:
>
> message = u"Comment was was added to '%s' by '%s': \n\n%s" % (self.post, 
> self.author, self.body)
>
> (I.e. Change the format string to a Unicode string)
>
> This is a common pitfall when dealing with user entered data.
>
> Bye
> Ulrich

-- 
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 get the test runner to only rebuild & populate the test_database if it changed?

2011-05-11 Thread Phlip
> Me again. Still helping clients TDD despite obese databases.

[localhost] run: python manage.py test --settings=test_settings my_app
--verbosity=0
--
Ran 2 tests in 0.018s

OK

Eat my vapor trail, b-words! Here's how I did it:

Upgrade the settings.py to use the TEST_NAME option:

DATABASES = {
'default': {
'NAME': 'test_myapp.db',
'TEST_NAME': 'test_myapp.db',
'ENGINE': 'django.db.backends.sqlite3', ...

Then wedge the test runner methods that were destroying and rebuilding
the database:


def setup_databases(self, **kwargs):
from django.db import connections
old_names = []
mirrors = []
for alias in connections:
connection = connections[alias]
# If the database is a test mirror, redirect it's connection
# instead of creating a test database.
if connection.settings_dict['TEST_MIRROR']:
mirrors.append((alias, connection))
mirror_alias = connection.settings_dict['TEST_MIRROR']
connections._connections[alias] =
connections[mirror_alias]
else:
old_names.append((connection,
connection.settings_dict['NAME']))
#connection.creation.create_test_db(self.verbosity,
autoclobber=not self.interactive)
return old_names, mirrors

def teardown_databases(self, old_config, **kwargs):
from django.db import connections
old_names, mirrors = old_config
# Point all the mirrors back to the originals
for alias, connection in mirrors:
connections._connections[alias] = connection
# Destroy all the non-mirror databases
#for connection, old_name in old_names:
#connection.creation.destroy_test_db(old_name, self.verbosity)

from django.test.simple import DjangoTestSuiteRunner

DjangoTestSuiteRunner.setup_databases = setup_databases
DjangoTestSuiteRunner.teardown_databases = teardown_databases

The next thing I'll need to do is rebuild the database only if the
models or .json files change.

I could add that to the wedge methods, above, or I could simply add a
"make" like system to the fabric fabfile.py that runs the test:

def test():
#  TODO  Check file time of test_myapp.db. If it's less than
my_app/models.py
   # or my_app/fixtures/my_app_database.json, rebuild the
db file

_sh('python manage.py test --settings=test_settings my_app --
verbosity=0')

This system now fully exploits sqlite3, especially its ability to
treat a transaction as a virtual ":memory:" database. It does not even
change the file time on the .db file when the tests run.

Could someone better at Django internals than me package this system
up and contrib it?

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand

-- 
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: DecimalFields, Floats, and Strings?

2011-05-11 Thread Nan
Yeah, I'm aware of the distinction between the types -- just wasn't
paying enough attention when I added the default and the filter, and
had to back up and take a second look when the filter started throwing
exceptions.  So basically it's a weird artifact of how defaults are
handled by the ORM?

On May 11, 3:11 pm, Shawn Milochik  wrote:
> On 05/11/2011 03:01 PM, Nan wrote:
>
> > Using Django 1.2.3, I recently declared a DecimalField on a model, and
> > it happily accepts a float as its default value, but it won't filter
> > on a float (it throws a TypeError instead).  Is there a reason for
> > this inconsistency?
>
> DecimalField subclasses Field, which forces the return value into
> unicode before returning it. This would explain why it accepts a default
> value of a float, but it's still technically incorrect to provide a
> float as a default value for a DecimalField.
>
> It is impossible to use a floating-point number to look up a Decimal,
> just because it is. That's why you can't look it up.
>
> It does look like a bit of a discrepancy, but the answer is that you
> should never be using floats with Decimal or DecimalField objects
> anyway. Even if it appears to work, there's always a very real chance
> that you think you're putting into your database isn't actually what
> you're putting into your database. Either pass a Decimal object or a
> string as the default value to your DecimalField.
>
> Shawn
>
> http://code.djangoproject.com/browser/django/trunk/django/db/models/f...

-- 
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: DecimalFields, Floats, and Strings?

2011-05-11 Thread Shawn Milochik

On 05/11/2011 05:26 PM, Nan wrote:

Yeah, I'm aware of the distinction between the types -- just wasn't
paying enough attention when I added the default and the filter, and
had to back up and take a second look when the filter started throwing
exceptions.  So basically it's a weird artifact of how defaults are
handled by the ORM?


No, this has nothing to do with the ORM itself, but rather the Field 
class of which DecimalField is a subclass. If you follow the link I sent 
earlier and read the code, you'll see that when you instantiate a Field 
(via a subclass such as DecimalField) and ask it for its default value, 
it calls a get_default function which converts the default value to 
unicode before returning it. In the case of a DecimalField, it makes it 
valid input for a decimal.Decimal declaration.



--
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: imagefield upload_to

2011-05-11 Thread Brian Craft
solved this by moving it to the model clean() method, and using
imagefield.file.open() and imagefield.file.read() to get the data for
computing the other fields.

On Wed, May 11, 2011 at 1:28 PM, Brian Craft  wrote:
> I have a model with an imagefield, and some fields that are computed
> from the image. I'm trying to override the "save" method to fill in
> the other fields.
>
> When I test this in the admin, there are two problems: first, the path
> (mymodel.image.path) doesn't honor the upload_to setting on the field.
> It concats MEDIA_ROOT and the file name, w/o the upload_to. (This is
> django 1.2.3). Second, I don't see the file in the filesystem when
> .save() is called. Perhaps save() is the wrong place to do this?
>
> If I don't try to generated the computed fields, the file is created
> in the correct (upload_to) directory, and if I read the object from
> the db, mymodel.image.path is also correct.
>
> Looks like upload_to is only accessed during FieldFile.save(), where
> the self.name is updated, so the path is always wrong before that.
>
> And apparently the file isn't committed to storage until the field is
> saved. Is there some other way to access the file before it is saved?
>

-- 
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 admin and static files

2011-05-11 Thread Juan Pablo Romero Méndez
Hello,

I'm trying to use a custom javascript file in the admin app with Media:


class MyAdmin(admin.ModelAdmin):
class Media:
js = ('js/my.js',)


the problem is that after installing the staticfiles app (in
INSTALLED_APPS) and after setting STATIC_URL = '/media/', the admin
app is unable to find their own admin files.


What could I do?

Regards,

  Juan Pablo

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



Tutorial: "Customize the admin look and feel"

2011-05-11 Thread BobG
Django users:

It is time to ask for help. I'm a newbie working the tutorial. I'm
using Linux Mint, Python 2.6, and Django 1.3. So far, everything has
been working smoothly, but I'm stuck on something that seems pretty
simple: "Customize the admin look and feel." I am unable to change
"Django administration" at the top of the page.

Here is the questionable line of code in settings.py:
TEMPLATE_DIRS = ("/home/bob/DjangoProjects/mysite/mytemplates/admin/
base_site.html",)

I have modified base_site.html as directed.

If the code is right, what should be in the admin directory?

Pax!

BobG

-- 
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: Tutorial: "Customize the admin look and feel"

2011-05-11 Thread Ramiro Morales
On Wed, May 11, 2011 at 8:39 PM, BobG  wrote:
> I'm stuck on something that seems pretty
> simple: "Customize the admin look and feel." I am unable to change
> "Django administration" at the top of the page.
>
> Here is the questionable line of code in settings.py:
> TEMPLATE_DIRS = ("/home/bob/DjangoProjects/mysite/mytemplates/admin/
> base_site.html",)

It should be

TEMPLATE_DIRS = ("/home/bob/DjangoProjects/mysite/mytemplates",)

Quoting from the relevant paragraph in that tutorial document:

[...] copy the template `admin/base_site.html` from within the default
Django admin template
directory in the source code of Django itself into an `admin`
subdirectory of whichever
directory you're using in TEMPLATE_DIRS.

-- 
Ramiro Morales

-- 
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.3 CSRF faild when upgraded from Django 1.2.5

2011-05-11 Thread 阮明辉
I had try it , but it did't work .
return render_to_response('account/login.html')
these code is invoke when the http post method is 'get'
but my problem is 'POST'
I add django.contrib.csrf.middleware.CsrfResponseMiddleware to my settings
and it can work
but I think this is not the best solution

2011/5/10 _ johnny . 

> Try add RequestContext in render_to_response()
>
> from django.template import RequestContext
>
> return render_to_response('account/login.html',
>> locals(), context_instance=RequestContext(request))
>
>
> On Tue, May 10, 2011 at 10:10 AM, 阮明辉  wrote:
>
>> return render_to_response('account/login.html')
>>
>
>  --
> 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.
>



-- 
Thanks & Regards,
ezioruan = {
'email':'qiaoqinq...@gamil.com',
'interests':{ 'Python',  'Linux' 'game'},
'location':'南京',
'website':'http://ezioandnanjing.appspot.com/',
'note':'功名利禄身外物,知足常乐总逍遥'
}

-- 
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: Tutorial: "Customize the admin look and feel"

2011-05-11 Thread BobG
Ramiro Morales:

Yep! Wowza! That did it. Thank you very much! Moving forward again!

Pax!

BobG

On May 11, 8:24 pm, Ramiro Morales  wrote:
> On Wed, May 11, 2011 at 8:39 PM, BobG  wrote:
> > I'm stuck on something that seems pretty
> > simple: "Customize the admin look and feel." I am unable to change
> > "Django administration" at the top of the page.
>
> > Here is the questionable line of code in settings.py:
> > TEMPLATE_DIRS = ("/home/bob/DjangoProjects/mysite/mytemplates/admin/
> > base_site.html",)
>
> It should be
>
> TEMPLATE_DIRS = ("/home/bob/DjangoProjects/mysite/mytemplates",)
>
> Quoting from the relevant paragraph in that tutorial document:
>
> [...] copy the template `admin/base_site.html` from within the default
> Django admin template
> directory in the source code of Django itself into an `admin`
> subdirectory of whichever
> directory you're using in TEMPLATE_DIRS.
>
> --
> Ramiro Morales

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



Overide error messages in models

2011-05-11 Thread Daniel França
Hi all,
I need to override error messages (like for required fields) directly in
Models, I don't wanna duplicate code declaring some fields again in forms,
and in some cases I don't even create the forms, just using generic views
for model...

I was looking for a solution to change the default error messages (without
write this in all fields), but I didn't find anything, so I look for a
solution to write the error messages right in Models, I found this:
http://docs.djangoproject.com/en/dev/ref/models/fields/#error-messages
I'm running django 1.2.5

I did that for some fields in my model, and the error message still is the
default message "This field is required".

Anyone know how can I solve that without need to duplicate code?

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



haystack

2011-05-11 Thread pankaj sharma
hello friends, i want to use haystack for my website,
but i am having too many problems to install it.
in the dowumentation it is telling to add haystack to ur installed
apps. now it it telling to do "HAYSTACK_SITECONF =
'myproject.search_sites'"
now where should i type this i dont have any idea about so please help
me

http://docs.haystacksearch.org/dev/tutorial.html

-- 
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 site and password field

2011-05-11 Thread Gabe
I am using built-in Django admin. In my models.py file password field
is defined:

password = models.CharField(max_length=64)

I just can`t see password type field for models.


On 11 Maj, 20:26, Shawn Milochik  wrote:
> It sounds like you're not using the built-in Django admin, which would
> make your life easier.
>
> Assuming you want to do it the hard way, you can just use a
> PasswordInput widget.http://docs.djangoproject.com/en/1.3/ref/forms/widgets/

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

2011-05-11 Thread Tarkeshwar Thakur
In your settings file
http://docs.djangoproject.com/en/dev/topics/settings/

On Thu, May 12, 2011 at 10:20 AM, pankaj sharma
wrote:

> hello friends, i want to use haystack for my website,
> but i am having too many problems to install it.
> in the dowumentation it is telling to add haystack to ur installed
> apps. now it it telling to do "HAYSTACK_SITECONF =
> 'myproject.search_sites'"
> now where should i type this i dont have any idea about so please help
> me
>
> http://docs.haystacksearch.org/dev/tutorial.html
>
> --
> 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.
>
>


-- 
- Tarkeshwar
Blog: tarkeshwar.com 
Pet project: operty.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.



customizing admin - third party db esp. MongoDB?

2011-05-11 Thread λq
Hi guys,

I have a legacy Django project to maintain, and now my job is to port some part
of the admin view from MySQL backend to MongoDB.

AFAIK the mongodb as Model backend for django isn't exactly mature
yet, I am thinking of writing customized admin views while using
PyMongo as mongodb driver.

So my question is: Is it possible to write complete overhaul of
django's admin with data provision from a third party? These includes wrap
around mongodb CURD operations, generate HTML forms and validating
data.

What's tbe best practice of doing this? Or am I just doing it wrong?

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



class based views

2011-05-11 Thread km
Hi all,

I do not find any help page on migrating existing function based views
(defined in views.py of django app) to class based views in django.1.3
pointers and help  appreciated.

regards,
KM

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