[ANN] Pycon India

2010-06-26 Thread Kenneth Gonsalves
hi,

for those of you who could be interested:
http://in.pycon.org/2010/cfp

for others - sorry for the noise
-- 
Regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS at AU-KBC

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



Error using inline displays with a user profile

2010-06-26 Thread derek
I am having some problems with inline displays, since I upgraded to
1.2.  The example here seems representative so I present as much
information as seems relevant.

I have set up the user & userprofile in a standard way - as per the
"recipe" given by James Bennett here:
http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/
and Matt's supplemental blog entry here:
http://www.thenestedfloat.com/articles/displaying-custom-user-profile-fields-in-djangos-admin

I have also checked that the userprofile table I use (basically the
old user table from the previous system, with an extra field added to
link it to the new auth_user) already contains all the data I want to
display/edit.

However, when I try and edit a user I get this error (which seems
related to the inline display somehow):

Request Method: GET
Request URL: http://127.0.0.1:8000/admin/auth/user/1/
Django Version: 1.2.1
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'sorl.thumbnail',
 'project.edit']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.middleware.csrf.CsrfResponseMiddleware',
 'edit.middleware.threadlocals.ThreadLocals')

Template error:
In template /project/edit/templates/admin/edit_inline/stacked.html,
error at line 8
   Caught TypeError while rendering: coercing to Unicode: need string
or buffer, NoneType found
   1 : {% load i18n adminmedia %}
   2 : 
   3 :   {{ inline_admin_formset.opts.verbose_name_plural|title }}

   4 : {{ inline_admin_formset.formset.management_form }}
   5 : {{ inline_admin_formset.formset.non_form_errors }}
   6 :
   7 : {% for inline_admin_form in inline_admin_formset %}
   8 :   {{ inline_admin_formset.opts.verbose_name|title }}: {% if inline_admin_form.original %}
{{ inline_admin_form.original }} {% else %}#{{ forloop.counter }}{%
endif %}


On the webpage, the {{ inline_admin_form.original }} is displayed in
red.

I have had this error in other places as well, but this seems the one
that is most easily reproducible.

Thanks
Derek

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



Re: Rendering the Admin app list?

2010-06-26 Thread derek
On Jun 25, 8:45 pm, raj  wrote:
> > Before I "pass the variable app_list"; do I not need to create what is
> > in this variable first?  If so, how?
>
> That template is rendered by the view, AdminSite.index() found at
> django.contrib.admin.sites. Please Check it to know how it's done.
>
> Rajeesh.

Will do.  I just find it very strange that, given I am working
in_and_with the Admin app, this routine works *only* in the index
page...

Derek

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



Re: Deployment hesitation after James Bennett's post, WSGI or ...?

2010-06-26 Thread Horst Gutmann


On 24 Jun 2010, at 12:15, Daniel Roseman  wrote:

> On Jun 24, 10:54 am, Dave E  wrote:
>> I'm about to enter my first deployment learning curve, but after
>> reading James Bennett's post 'Let’s talk about WSGI' (http://www.b-
>> list.org/weblog/2009/aug/10/wsgi/) and further procrastinating by
>> reading through a whole pile of (horribly varying) tutorials and WSGI
>> guides, I'd like to know:
>> 
>> 1. what the Django deployment wisdom is for the near future?
> 
> WSGI. Absolutely no question about it.
> 
>> 2. whether it's really worth running lighttpd (or whatever) for static
>> files on small-scale sites (say, where there's just a blog and a few
>> rarely-altered pages)?
> 
> No, not really. For that setup, a single Apache instance is fine.
> 
>> (My very small partnership runs Apache2 on a Linux VPS server (Debian
>> 5.0.4/Lenny with 512 MB).
> 

For this kind of setup I can really recommend going with nginx + fcgi or 
gunicorn. Do you require Apache for other parts of your setup? If not then it 
is worth considering getting rid of it.

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

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



Re: New project, debating postgresql or MySQL (Amazon RDS), does it matter to Django?

2010-06-26 Thread Tomasz Zieliński
On 25 Cze, 19:13, Eric Chamberlain  wrote:
> Hello,
>
> We have a new project and are debating whether to use postrgresql (Amazon 
> EC2) or MySQL with InnoDB tables (Amazon RDS).  It looks like our TCO would 
> be much lower using Amazon RDS.
>
> Our past Django experience has been with postgresql, does MySQL InnoDB have 
> any problems with Django's transaction middleware?
>
> We aren't using any custom fields, are there functional differences between 
> the two databases that would impact how we use Django?  
>

Take a look at this: 
http://www.slideshare.net/gplessis/mysql-on-amazon-rds-vs-ec2
RDS is pretty much a no-brainer, but it cannot be tuned like a custom
instance.

Regarding transactions - I have experience with one medium-sized
startup running on RDS (so it's MySQL+Innodb, formerly it was custom
instance but they switched for convenience), and things Just Work As
Advertised, but you have to remember about one subtle detail, that I
once commented here:

http://stackoverflow.com/questions/2235318/how-do-i-deal-with-this-race-condition-in-django/2235624#2235624

Other than that everything has so far been smooth, at least in my
operations.

Ah, and to save you pulling your hair:
- create MySQL database with CREATE DATABASE name CHARACTER SET UTF8;
- set DATABASE_OPTIONS to {"init_command": "SET
storage_engine=INNODB",}, at least for syncdb. Otherwise your tables
might be created as MyISAM.
Both of these are documented:
http://docs.djangoproject.com/en/dev/ref/databases/#creating-your-database
http://docs.djangoproject.com/en/dev/ref/databases/#creating-your-tables
- but it's easy to overlook them

As for comparision between MySql+InnoDb and PostgreSQL, I don't have
that much experience with the latter so I won't comment on this.
Two transaction-related differences that I'm aware of are:
- PostreSQL requires ROLLBACK of failed transaction, whereas MySQL
doesn't;
- MySQL backend doesn't support savepoints, even though MySQL itself
handles them. I asked this question on this group some time ago
(http://groups.google.com/group/django-users/browse_thread/thread/
ea3421933ea8c199), but noone answered.

--
Tomasz Zielinski
http://pyconsultant.eu

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



Re: Error using inline displays with a user profile

2010-06-26 Thread Karen Tracey
On Sat, Jun 26, 2010 at 3:48 AM, derek  wrote:

>   Caught TypeError while rendering: coercing to Unicode: need string
> or buffer, NoneType found
>

The typical reason for this message is a __unicode__ method for a model that
is not returning unicode. The traceback would help to reveal whether that is
what is going on in this case or if it is something else.

Karen
-- 
http://tracey.org/kmt/

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



generate localized message

2010-06-26 Thread tsmets
My django application root directory on my Mac is :
/Users/tsmets/Documents/python//
Under that folder I have the following directory structure :

Thomas-SMETSs-MacBook-Pro: tsmets$ find .  -d 1

./.svn
./__init__.py
./Base
./clean_unused.sh
./constants.py
./fixtures
./formats
./Health
./InfoAndNews
./load_data.sh
./locale
./logging.conf
./manage.py
./scripts
./settings.py
./Sport
./templates
./test_constants.py
./urls.py
...

with as Django module : Base / Health / InfoAndNews / Sport

Willing to make my Site support multiple languages, I switched some
"Strings" to their _("Strings") version and I am now will to generated
the translated versions.
After struggling a bit (it is always good), I exported the following
variable :
DJANGO_SETTINGS_MODULE=/Users/tsmets/Documents/python//


Now, when I run the command to generate the message


Thomas-SMETSs-MacBook-Pro: tsmets$ django-admin.py  makemessages
-v 2 -a
examining files with the extensions: .html
processing language ca
ignoring file all-wcprops in ./.svn
ignoring file entries in ./.svn
ignoring file __init__.py.svn-base in ./.svn/prop-base
ignoring file clean_unused.sh.svn-base in ./.svn/prop-base
ignoring file constants.py.svn-base in ./.svn/prop-base
ignoring file load_data.sh.svn-base in ./.svn/prop-base
ignoring file logging.conf.svn-base in ./.svn/prop-base
ignoring file manage.py.svn-base in ./.svn/prop-base
ignoring file settings.py.svn-base in ./.svn/prop-base
ignoring file urls.py.svn-base in ./.svn/prop-base
ignoring file __init__.py.svn-base in ./.svn/text-base
ignoring file clean_unused.sh.svn-base in ./.svn/text-base
ignoring file constants.py.svn-base in ./.svn/text-base
ignoring file load_data.sh.svn-base in ./.svn/text-base
ignoring file logging.conf.svn-base in ./.svn/text-base
ignoring file manage.py.svn-base in ./.svn/text-base
ignoring file settings.py.svn-base in ./.svn/text-base
ignoring file urls.py.svn-base in ./.svn/text-base
processing file __init__.py in .
Error: errors happened while running xgettext on __init__.py
/bin/sh: xgettext: command not found

Thomas-SMETSs-MacBook-Pro: tsmets$ xgettext
xgettext.plxgettext5.10.0.pl  xgettext5.8.9.pl



Any idea ... what's wrong  ?

\T,


ps : I send a mail to the list through my GMail account --> Nothing
came up in the list.
When accessing the page http://groups.google.com/group/django-users/,
if I wanted to post, Google was redirecting to & fro in a endless
loop ... Now from ubuntu it seems OK

--
Thomas SMETS
rue J. Wytsmanstraat 62
1050 Brussels
m. : +32 497 44 68 12
W : http://genealogy.tsmets.lautre.net
skype : tsmets

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



Re: Rendering the Admin app list?

2010-06-26 Thread euan.godd...@googlemail.com
There is no reason why all views should pass that variable to the
template. It is more efficient to only pass the minimal variable
necessary to render the template Even the list is lazily evaluated
there is still unnecessary overhead in passing it when not needed.

Euan

On 26 June, 08:50, derek  wrote:
> On Jun 25, 8:45 pm, raj  wrote:
>
> > > Before I "pass the variable app_list"; do I not need to create what is
> > > in this variable first?  If so, how?
>
> > That template is rendered by the view, AdminSite.index() found at
> > django.contrib.admin.sites. Please Check it to know how it's done.
>
> > Rajeesh.
>
> Will do.  I just find it very strange that, given I am working
> in_and_with the Admin app, this routine works *only* in the index
> page...
>
> Derek

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



Re: Why is ModelAdmin to Model a 1-1 relationship?

2010-06-26 Thread euan.godd...@googlemail.com
It may be possible to sub-class admin.ModelAdmin so that when your two
instances are registered the code won't throw an exception. I suspect
it might be a bit nasty as many such things in Django are often
fraught when you stray off the beaten path.

If I get a chance I'll take a look at the source and see if I can see
any way to do it.

That is an interesting idea overriding the delete method. We have a
similar flag on most of our models, but explicitly set the flag and
then save. Your suggestion is great, because it stops things being
deleted in even Django admin.

Good luck, Euan

On 25 June, 22:54, patjenk  wrote:
> In our application, we have a Model that has a boolean field named
> "deleted". When the delete() method is called, we set the deleted
> field to 1 and then save the model. We would like to create an admin
> site where we can manage the deleted and non deleted instances
> separately.
>
> We could accomplish our goal by defining a queryset function for the
> ModelAdmin that restricts the instances returned to deleted=0.
> However, AFAIK this would eliminate the ability to undelete instances
> via the admin. Another option is to allow all instances to be shown
> and include delete as a value in the list_filter list for the admin
> but that clutters up our UI and requires an extra click. It would be
> nice if we could specify that the default admin view for this model
> has a list_filter of deleted=0 but I don't think this is currently
> possible.
>
> I think a good solution would be to create two ModelAdmins. One to
> display active instances and one to display deleted instances. With
> this approach we could define a queryset function for each ModelAdmin
> and when an instance is deleted it would automatically move to the
> correct ModelAdmin. This is explicitly denied in django/contrib/admin/
> sites.py. Simply removing this check does not solve our problem but
> overwrites the first ModelAdmin for the model with the second via the
> dictionary "_registered" in the AdminSite class. From my brief dive
> into the admin site, there doesn't appear to be a real need for a one
> to one relationship between ModelAdmins and Models. If you allowed
> ModelAdmins to specify their own name I think it would be possible to
> have more than one ModelAdmin for a Model. I am not a Django expert
> but I don't see a reason that this scenario should be excluded.
>
> Can anyone recommend a way to accomplish either of the approaches I
> outlined above or propose a new approach that does not violate the
> AdminSite rules? Also, if anyone knows why the ModelAdmin needs to
> have a one to one relationship with Model please let me know.

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



Re: New project, debating postgresql or MySQL (Amazon RDS), does it matter to Django?

2010-06-26 Thread creecode
Hello all,

On Jun 26, 5:46 am, Tomasz Zieliński
 wrote:

> Ah, and to save you pulling your hair:
> - create MySQL database with CREATE DATABASE name CHARACTER SET UTF8;
> - set DATABASE_OPTIONS to {"init_command": "SET
> storage_engine=INNODB",}, at least for syncdb. Otherwise your tables
> might be created as MyISAM.
> Both of these are 
> documented:http://docs.djangoproject.com/en/dev/ref/databases/#creating-your-dat...http://docs.djangoproject.com/en/dev/ref/databases/#creating-your-tables
> - but it's easy to overlook them

There is nothing wrong with MyISAM tables, if they meet the needs of
your application.  In some cases I think they are required; for full
text searching if I recall correctly.

The docs are just pointing out one way to change the storage type for
your tables if needed.

Toodle-l
creecode

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



include and ifchanged inconsistent behavior (variables vs. strings)

2010-06-26 Thread Jerry Stratton
I often loop through lists, but for the guts of the list use "include"
because the same code is needed in multiple places.

Inside the included files, "ifchanged" works, but only as long as the
include is done by way of a string. I recently changed a template that
was a complex mess of IFs to instead use template inheritance and have
my page object return the appropriate template to include, and
ifchanged stopped working.

Simple example:

MODELS.PY

class Page(models.Model):
...
def worlds(self):
return ['Mercury', 'Venus', 'Venus', 'Earth', 'Earth', 'Earth',
'Mars', 'Mars', 'Mars', 'Mars']

def helloTemplate(self):
return 'test/world.html'


VIEWS.PY

def test(request):
page = Page.objects.get(slug='mimsy') #just to get an object with
those methods on it
return render_to_response('test/hello.html', {'page': page})


TEST/HELLO.HTML

As string

{% for world in page.worlds %}
{% include "test/world.html" %}
{% endfor %}

As variable

{% for world in page.worlds %}
{% include page.helloTemplate %}
{% endfor %}

TEST/WORLD.HTML

{% ifchanged %}Hello {{ world }}{% endifchanged %}

RESULT:

As string

Hello Mercury
Hello Venus
Hello Earth
Hello Mars


As variable

Hello Mercury
Hello Venus
Hello Venus
Hello Earth
Hello Earth
Hello Earth
Hello Mars
Hello Mars
Hello Mars
Hello Mars

Is this a bug? And if it is, which of those results is correct?



Here's my real-world example:

def linkDefinition(self):
return 'parts/dd/' + self.organize_URLs_by + '.html'


{% for link in links %}
{% include page.linkDefinition %}
{% endfor %}

vs.

{% for link in links %}
{% ifequal page.linkDefinition "parts/dd/title.html" %}
{% include "parts/dd/title.html" %}
{% else %}
{% ifequal page.linkDefinition "parts/dd/category.html" %}
{% include "parts/dd/category.html" %}
{% else %}
{% ifequal page.linkDefinition "parts/dd/author.html" %}
{% include "parts/dd/author.html" %}
{% else %}
{% ifequal page.linkDefinition 
"parts/dd/content.html" %}
{% include "parts/dd/content.html" %}
{% else %}
{% ifequal page.linkDefinition 
"parts/dd/d6-icon.html" %}
{% include 
"parts/dd/d6-icon.html" %}
{% endifequal %}
{% endifequal %}
{% endifequal %}
{% endifequal %}
{% endifequal %}
{% endfor %}

I can move that mess off into its own include file (I've tested it),
but can I even do an include inside of a loop and expect ifchanged to
work in the future?

Jerry

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



Re: include and ifchanged inconsistent behavior (variables vs. strings)

2010-06-26 Thread Jerry Stratton
Sorry, forgot to mention, I'm using Django 1.2.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



formfield_for_foreignkey: how to know if we are modifyng an entry

2010-06-26 Thread drakkan
Hi,

I'm customizing the django admin and I need to do a particular filter
for a foreign key if I'm modifying a model, I'm using the following
method, it works but it seems to me an hack, is there a better way to
do the same thing?

def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "domain":
mod=False
ID=-1
for val in request.path.split('/'):
try:
ID=int(val)
mod=True
break
except:
pass
if mod:
m_user=MailUser.objects.get(pk=ID)
kwargs["queryset"] = 
Domain.objects.filter(id=m_user.domain_id)
..
return db_field.formfield(**kwargs)
.

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



PyConAU2010

2010-06-26 Thread Peter Williams

Hi all

PyConAu 2010, currently in progress in Sydney, Australia, is proving 
very successful and informative.  There have been several excellent 
speakers with topics on Django, not to mention all of the Python talks.  
The 200 or so attendees and presenters are from all walks of life, age 
groups etc.  Fortunately, I live within easy travelling distance from 
Sydney, and conferences like this are amongst my few opportunities for 
professional development.  They boost my enthusiasm for the technologies 
which allow my organisation to develop systems, for staff and external 
stakeholders, efficiently and cost effectively.  I would like to 
congratulate the organising committee of this first PyConAu for doing a 
wonderful job.


Thanks.

Peter

Peter J Williams
Information Manager
NSW Rural Doctors Network
Head Office
Suite 19, Level 3
133 King Street
Newcastle NSW 2300
Telephone: (02) 4924-8000
Facsimile: (02) 4924-8010
Mailto:pwilli...@nswrdn.com.au
Web: http://www.nswrdn.com.au


Disclaimer: This email, including the attachments, is intended for the 
addressee named and may contain confidential information. If you are not the 
intended recipient, please notify us by return email and then delete this email 
and your reply. Views expressed in this message are those of the individual 
sender, and are not necessarily the views of NSW Rural Doctors Network.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PyConAU2010

2010-06-26 Thread Tran Cao Thai
What a pity! i live in Melbourne :((. Hope that i can join it some day

On Sun, 2010-06-27 at 12:43 +1000, Peter Williams wrote: 
> Hi all
> 
> PyConAu 2010, currently in progress in Sydney, Australia, is proving 
> very successful and informative.  There have been several excellent 
> speakers with topics on Django, not to mention all of the Python talks.  
> The 200 or so attendees and presenters are from all walks of life, age 
> groups etc.  Fortunately, I live within easy travelling distance from 
> Sydney, and conferences like this are amongst my few opportunities for 
> professional development.  They boost my enthusiasm for the technologies 
> which allow my organisation to develop systems, for staff and external 
> stakeholders, efficiently and cost effectively.  I would like to 
> congratulate the organising committee of this first PyConAu for doing a 
> wonderful job.
> 
> Thanks.
> 
> Peter
> 
> Peter J Williams
> Information Manager
> NSW Rural Doctors Network
> Head Office
> Suite 19, Level 3
> 133 King Street
> Newcastle NSW 2300
> Telephone: (02) 4924-8000
> Facsimile: (02) 4924-8010
> Mailto:pwilli...@nswrdn.com.au
> Web: http://www.nswrdn.com.au
> 
> 
> plain text document attachment (disclaimer.txt)
> Disclaimer: This email, including the attachments, is intended for the 
> addressee named and may contain confidential information. If you are not the 
> intended recipient, please notify us by return email and then delete this 
> email and your reply. Views expressed in this message are those of the 
> individual sender, and are not necessarily the views of NSW Rural Doctors 
> Network.



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



Re: Why is ModelAdmin to Model a 1-1 relationship?

2010-06-26 Thread Lee Hinde
On Fri, Jun 25, 2010 at 2:54 PM, patjenk  wrote:
> In our application, we have a Model that has a boolean field named
> "deleted". When the delete() method is called, we set the deleted
> field to 1 and then save the model. We would like to create an admin
> site where we can manage the deleted and non deleted instances
> separately.
>
> We could accomplish our goal by defining a queryset function for the
> ModelAdmin that restricts the instances returned to deleted=0.
> However, AFAIK this would eliminate the ability to undelete instances
> via the admin. Another option is to allow all instances to be shown
> and include delete as a value in the list_filter list for the admin
> but that clutters up our UI and requires an extra click. It would be
> nice if we could specify that the default admin view for this model
> has a list_filter of deleted=0 but I don't think this is currently
> possible.
>
> I think a good solution would be to create two ModelAdmins. One to
> display active instances and one to display deleted instances. With
> this approach we could define a queryset function for each ModelAdmin
> and when an instance is deleted it would automatically move to the
> correct ModelAdmin. This is explicitly denied in django/contrib/admin/
> sites.py. Simply removing this check does not solve our problem but
> overwrites the first ModelAdmin for the model with the second via the
> dictionary "_registered" in the AdminSite class. From my brief dive
> into the admin site, there doesn't appear to be a real need for a one
> to one relationship between ModelAdmins and Models. If you allowed
> ModelAdmins to specify their own name I think it would be possible to
> have more than one ModelAdmin for a Model. I am not a Django expert
> but I don't see a reason that this scenario should be excluded.
>
> Can anyone recommend a way to accomplish either of the approaches I
> outlined above or propose a new approach that does not violate the
> AdminSite rules? Also, if anyone knows why the ModelAdmin needs to
> have a one to one relationship with Model please let me know.

I recently clipped this for future reference. I believe it will help
you do what you want:

http://www.mahner.org/posts/separating-staff-and-user-accounts-in-djangos-admin/

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



Custom widgets in Model Formsets

2010-06-26 Thread ses1984
I am trying to use custom widgets in a model formset. I have tried to
achieve this by first defining the custom widget, then a form that
uses this widget, then passing this form as an argument to
modelformset_factory().

I don't think something is working right because if I check the type
of the form objects in my formset, the objects are my own custom
SliderInputs; however, when the very same formset is rendered, it
renders like the default widget. They don't render with any of the
content that I have added to the render method of SliderInput.

Below is the shell session demonstrating that I have SliderInput
widgets, then the actual class code that defines these.

I am using Django 1.1.1.


>>> from fd.access.models import Flavor, Recipe
>>> from fd.access.forms import WeightSliderForm
>>> from django.forms.models import modelformset_factory
>>>
>>> flavor = Flavor.objects.all()[1]
>>>
>>> RecipeFormSet = modelformset_factory(Recipe, form=WeightSliderForm)
>>> recipe_formset = RecipeFormSet(queryset=flavor.recipe_set.all())
>>>
>>> for recipe_form in recipe_formset.forms:
... print recipe_form.Meta.widgets
...
{'amount': }
{'amount': }
{'amount': }
{'amount': }
{'amount': }
>>>

###

class SliderInput(forms.widgets.TextInput):
"""
A slider widget to include in your form
"""

def render(self, name, value, attrs):
attributes = attrs
attributes['type'] = 'hidden'

res = super(SliderInput, self).render(name, value, attrs =
attributes)
res += ''
res += '%d' % (name, value)
res += '' %
name
res += '' % name
res += ''
return res

class Media:
css = {'screen':('/media/css/widgets/slider.css',)}
js = ('/media/js/widgets/slider.js',)

class WeightSliderForm(forms.ModelForm):
class Meta:
model = Recipe
fields = ['amount']
widgets = {
   'amount': SliderInput(attrs={
 'max':'1000',
 'min':'0',
 'step':'.001',
 'unit':'%',
 }),
   }

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