Re: rendering values from ManyToMany fields

2009-04-13 Thread Adam Fraser

figured it out!

class ModelForm(forms.ModelForm):
'''
Define our own model forms so we can use the form to render a
read-only detail page.
'''
def __init__(self, *args, **kwargs):
readonly = kwargs.get('readonly', False)
if readonly:
del kwargs['readonly']
super(ModelForm, self).__init__(*args, **kwargs)
if readonly:
obj = self.instance
for field_name in self.fields:
if hasattr(obj, 'get_%s_display' % field_name):
display_value = getattr(obj, 'get_%s_display' %
field_name)()
else:
# ---
# for fields that don't have a get_FIELD_display,
try to join the values manually in a  separated list.
try:
display_value = ''.join([unicode(x) for x
in getattr(obj, field_name).get_query_set()])
except:
display_value = None
# --
self.fields[field_name].widget = ReadOnlyWidget(getattr
(obj, field_name, ''), display_value)


On Apr 13, 9:54 am, Adam Fraser <adam.n.fra...@gmail.com> wrote:
> Okay, so I should probably be dealing with the field in my ModelForm
> class (the one that subclasses ModelForm).
>
> This code is where the display values are found before creating the
> ReadOnlyWidget.  In the case of my stains field (a ManyToMany field),
> there isn't a get_stains_display function, so there's no way of
> displaying it nicely (yet).
>
> for field_name in self.fields:
>                 if hasattr(obj, 'get_%s_display' % field_name):
>                     display_value = getattr(obj, 'get_%s_display' %
> field_name)()
>                 else:
>                     # what to do?
>                     display_value = None
>                 self.fields[field_name].widget = ReadOnlyWidget(getattr
> (obj, field_name, ''), display_value)
>
> I assume the get_XXX_display functions are being defined automatically
> for my other fields in the project model (all of which are
> PositiveIntegerFields).  How do I define one to get the display value
> (s) for my stains ManyToManyField which maps to this model?
>
> class Stain(models.Model):
>     def __unicode__(self):
>         return unicode(self.name)
>     name = models.CharField(max_length=40)
>
> On Apr 10, 7:31 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
> wrote:
>
> > On Fri, 2009-04-10 at 12:16 -0700, Adam Fraser wrote:
>
> > [...]
>
> > > The problem I'm running into is that the value that comes into render
> > > for the ManyToManyField is a list of the id's for the selected stains
> > > and not the stains themselves.  I assume I should be getting them
> > > somehow through the django.db.models.fields.related.ManyRelatedManager
> > > which is in the original_value, but I haven't been able to figure out
> > > how.
>
> > > Anyone know what I'm missing?
>
> > The Widget subclass should only be processing the data that is going to
> > be displayed on the form. For something like a choice field based on
> > models, this would be, say, the pk value and a string to use for the
> > human-readable portion.
>
> > The django.forms.models.ModelChoiceField is a good example to look at to
> > see what's going on. It uses ModelChoiceIterator.choice() to generate
> > the data that is passed to the widget for rendering and you'll see that
> > it returns (pk, label) pairs.
>
> > So it sounds like things are working as expected. What extra work are
> > you trying to do at the widget level that requires more than what is
> > already passed in (the sequence of (pk, label) values)? Why isn't
> > whatever field you're using generating the right data? It's the Field
> > subclass that you want to be addressing here, not the widget.
>
> > In summary, widgets are objects that know how to take flat data and
> > convert it to HTML. Fields are objects that know how to take more
> > complex Python things (models, arbitrary objects, ...) and convert them
> > to flat data for passing to the widgets.
>
> > Regards,
> > Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: rendering values from ManyToMany fields

2009-04-13 Thread Adam Fraser

Okay, so I should probably be dealing with the field in my ModelForm
class (the one that subclasses ModelForm).

This code is where the display values are found before creating the
ReadOnlyWidget.  In the case of my stains field (a ManyToMany field),
there isn't a get_stains_display function, so there's no way of
displaying it nicely (yet).

for field_name in self.fields:
if hasattr(obj, 'get_%s_display' % field_name):
display_value = getattr(obj, 'get_%s_display' %
field_name)()
else:
# what to do?
display_value = None
self.fields[field_name].widget = ReadOnlyWidget(getattr
(obj, field_name, ''), display_value)

I assume the get_XXX_display functions are being defined automatically
for my other fields in the project model (all of which are
PositiveIntegerFields).  How do I define one to get the display value
(s) for my stains ManyToManyField which maps to this model?

class Stain(models.Model):
def __unicode__(self):
return unicode(self.name)
name = models.CharField(max_length=40)


On Apr 10, 7:31 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Fri, 2009-04-10 at 12:16 -0700, Adam Fraser wrote:
>
> [...]
>
> > The problem I'm running into is that the value that comes into render
> > for the ManyToManyField is a list of the id's for the selected stains
> > and not the stains themselves.  I assume I should be getting them
> > somehow through the django.db.models.fields.related.ManyRelatedManager
> > which is in the original_value, but I haven't been able to figure out
> > how.
>
> > Anyone know what I'm missing?
>
> The Widget subclass should only be processing the data that is going to
> be displayed on the form. For something like a choice field based on
> models, this would be, say, the pk value and a string to use for the
> human-readable portion.
>
> The django.forms.models.ModelChoiceField is a good example to look at to
> see what's going on. It uses ModelChoiceIterator.choice() to generate
> the data that is passed to the widget for rendering and you'll see that
> it returns (pk, label) pairs.
>
> So it sounds like things are working as expected. What extra work are
> you trying to do at the widget level that requires more than what is
> already passed in (the sequence of (pk, label) values)? Why isn't
> whatever field you're using generating the right data? It's the Field
> subclass that you want to be addressing here, not the widget.
>
> In summary, widgets are objects that know how to take flat data and
> convert it to HTML. Fields are objects that know how to take more
> complex Python things (models, arbitrary objects, ...) and convert them
> to flat data for passing to the widgets.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



rendering values from ManyToMany fields

2009-04-10 Thread Adam Fraser

Hello,

I'm using a ManyToManyField to model a relationship where a "Project"
object may have many different "Stain" objects.  The code is working
successfully and looks like this

class Stain(models.Model):
def __unicode__(self):
return unicode(self.name)
name = models.CharField(max_length=40)

class Project(models.Model):
name = models.CharField(max_length=200)
stains = models.ManyToManyField(Stain, blank=True) # not required
...


However, I've also subclassed ModelForm in the interest of defining a
readonly view of the Project data (ie: a view without inputs).  The
code in forms.py is like this:

class ReadOnlyWidget(forms.Widget):
'''
Widget used by our ModelForm when rendering in readonly mode.
'''
def __init__(self, original_value, display_value):
self.original_value = original_value
self.display_value = display_value
super(ReadOnlyWidget, self).__init__()

def render(self, name, value, attrs=None):
if self.display_value is not None:
return unicode(self.display_value)
if type(value) == list:
#
#  Need to format list fields so they're seen in read only
view
#
return unicode(value)
return unicode(self.original_value)

def value_from_datadict(self, data, files, name):
return self.original_value

class ModelForm(forms.ModelForm):
'''
Define our own model forms so we can use the form to render a
read-only detail page.
'''
def __init__(self, *args, **kwargs):
readonly = kwargs.get('readonly', False)
if readonly:
del kwargs['readonly']
super(ModelForm, self).__init__(*args, **kwargs)
if readonly:
obj = self.instance
for field_name in self.fields:
if hasattr(obj, 'get_%s_display' % field_name):
display_value = getattr(obj,
'get_%s_display' %
field_name)()
else:
display_value = None
self.fields[field_name].widget = ReadOnlyWidget(getattr
(obj, field_name, ''), display_value)

class ProjectForm(ModelForm):
class Meta:
model = Project



The problem I'm running into is that the value that comes into render
for the ManyToManyField is a list of the id's for the selected stains
and not the stains themselves.  I assume I should be getting them
somehow through the django.db.models.fields.related.ManyRelatedManager
which is in the original_value, but I haven't been able to figure out
how.

Anyone know what I'm missing?
--~--~-~--~~~---~--~~
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: need a multiselect list box for a static list of options

2009-04-07 Thread Adam Fraser

Yup:
>>> django.get_version()
u'0.97-pre-SVN-unknown'

On Apr 6, 1:45 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Mon, Apr 6, 2009 at 1:40 PM, Adam Fraser <adam.n.fra...@gmail.com> wrote:
>
> > Yeah, I just realized I'm running django 0.97
>
> > On Apr 6, 1:32 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> > > On Mon, Apr 6, 2009 at 11:57 AM, Adam Fraser <adam.n.fra...@gmail.com
> > >wrote:
>
> > > > Does anyone have a clue why I can't access ModelAdmin in
> > > > django.contrib.admin?
>
> > > > >>> from django.contrib import admin
> > > > >>> dir(admin)
> > > > ['__builtins__', '__doc__', '__file__', '__name__', '__path__',
> > > > 'models']
>
> > > > ???
>
> > > That's the result I get if my PYTHONPATH is pointing to a 0.96.x version
> > of
> > > Django.
>
> > > Karen
>
> There is no Django .97, presumably you mean some SVN version after .96.
>
> 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
--~--~-~--~~~---~--~~
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: need a multiselect list box for a static list of options

2009-04-06 Thread Adam Fraser

Yeah, I just realized I'm running django 0.97

On Apr 6, 1:32 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Mon, Apr 6, 2009 at 11:57 AM, Adam Fraser <adam.n.fra...@gmail.com>wrote:
>
>
>
> > Does anyone have a clue why I can't access ModelAdmin in
> > django.contrib.admin?
>
> > >>> from django.contrib import admin
> > >>> dir(admin)
> > ['__builtins__', '__doc__', '__file__', '__name__', '__path__',
> > 'models']
>
> > ???
>
> That's the result I get if my PYTHONPATH is pointing to a 0.96.x version of
> Django.
>
> 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: need a multiselect list box for a static list of options

2009-04-06 Thread Adam Fraser

Does anyone have a clue why I can't access ModelAdmin in
django.contrib.admin?

>>> from django.contrib import admin
>>> dir(admin)
['__builtins__', '__doc__', '__file__', '__name__', '__path__',
'models']

???

I'm trying to do this:

class ProjectAdmin(admin.ModelAdmin):
formfield_overrides = {
models.CommaSeparatedIntegerField: {'widget':
forms.SelectMultiple},
}

admin.site.register(Project, ProjectAdmin)


OR this

class ProjectAdmin(admin.ModelAdmin):
form = ProjectForm

admin.site.register(Project, ProjectAdmin)

class ProjectForm(forms.ModelForm):
class Meta:
model = Project
stains = forms.CommaSeparatedIntegerField
(widget=forms.SelectMultiple(choices=STAINS_CHOICES))

but I can't figure out what I'm doing wrong.

-Adam

On Mar 26, 2:08 pm, Adam Fraser <adam.n.fra...@gmail.com> wrote:
> First, I want to thank you for sticking with me and helping me through
> this.  I've learned a lot, but unfortunately made no progress yet.
>
> I read the links you sent and ended up trying this in forms.py:
>
> from django.contrib import admin
> class ProjectAdmin(admin.ModelAdmin):
>     formfield_overrides = {
>         models.CommaSeparatedIntegerField: {'widget':
> forms.SelectMultiple},
>     }
>
> but I get an error " 'module' object has no attribute 'ModelAdmin' "
> (I verified this from python manage.py shell)
>
> My guess is I'm using an older django distribution.  Unfortunately,
> this isn't something I can update since it's on a server I have
> limited access to.
>
> Before taking this tack, I was trying something like this (again, in
> forms.py)
> (http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overrid...
> )
>
> class ProjectForm(forms.ModelForm):
>     stains = forms.CommaSeparatedIntegerField
> (widget=forms.SelectMultiple(choices=STAINS_CHOICES))
>     class Meta:
>         model = Project
>
> ...with this I get a strange error:
> ViewDoesNotExist at /projectprofiler/admin/projects/project/504/
> Tried logout_view in module projectprofiler.projects.views. Error was:
> 'module' object has no attribute 'CommaSeparatedIntegerField'
> Request Method:         GET
> Request URL:    
> http://imageweb.broad.mit.edu:8081/projectprofiler/admin/projects/pro...
> Exception Type:         ViewDoesNotExist
> Exception Value:        Tried logout_view in module
> projectprofiler.projects.views. Error was: 'module' object has no
> attribute 'CommaSeparatedIntegerField'
> Exception Location:     /imaging/analysis/People/imageweb/python-packages/
> django/core/urlresolvers.py in _get_callback, line 184
> ...
> In template /home/radon01/afraser/projectprofiler/templates/admin/
> base.html, error at line 28
> 28    {% trans 'Change password' %}
>
> ...I can't figure out what the password_change view as to do with the
> commaseparatedintegerfield.
>
> Thanks again  :]
> Adam
>
> On Mar 26, 11:39 am, Brian Neal <bgn...@gmail.com> wrote:
>
> > On Mar 26, 9:59 am, Adam Fraser <adam.n.fra...@gmail.com> wrote:
>
> > > hrm, I think I'm _finally_ starting to understand how django is meant
> > > to be used.
>
> > > Question: Why can't I just specify the widget used by a particular
> > > field from my model in the admin interface.
>
> > > stains = models.CommaSeparatedIntegerField(widget=SelectMultiple
> > > (choices=STAIN_CHOICES))
>
> > > ...or can I?  You suggested something like this earlier only referred
> > > to forms.CommaSeparatedIntegerField rather than
> > > models.CommaSeparatedIntegerField.
>
> > > hrm
>
> > Models are simply models. They don't really say much about forms. What
> > the admin application does is to make some default choices about how
> > to display your model in the admin interface. It automatically builds
> > the form to edit your model using some very reasonable defaults. If
> > you aren't happy with those choices, you can provide the form that the
> > admin should use instead of the default one. In your form, you are
> > free to use different widgets for your fields and/or provide custom
> > behavior.
>
> > The docs describe how to provide your own form to the admin 
> > here:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#form
>
> > You simply provide an attribute on your ModelAdmin called 'form', set
> > equal to the form class you want the admin to use. This form class
> > should inherit from ModelForm. You can then customize the widgets and
> > behavior anyway you would like.
>
> > ModelForms are discussed 
> > here:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#topics-...
>
> > Overr

Re: need a multiselect list box for a static list of options

2009-03-26 Thread Adam Fraser

First, I want to thank you for sticking with me and helping me through
this.  I've learned a lot, but unfortunately made no progress yet.

I read the links you sent and ended up trying this in forms.py:

from django.contrib import admin
class ProjectAdmin(admin.ModelAdmin):
formfield_overrides = {
models.CommaSeparatedIntegerField: {'widget':
forms.SelectMultiple},
}

but I get an error " 'module' object has no attribute 'ModelAdmin' "
(I verified this from python manage.py shell)

My guess is I'm using an older django distribution.  Unfortunately,
this isn't something I can update since it's on a server I have
limited access to.

Before taking this tack, I was trying something like this (again, in
forms.py)
( 
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-field-types
)

class ProjectForm(forms.ModelForm):
stains = forms.CommaSeparatedIntegerField
(widget=forms.SelectMultiple(choices=STAINS_CHOICES))
class Meta:
model = Project

...with this I get a strange error:
ViewDoesNotExist at /projectprofiler/admin/projects/project/504/
Tried logout_view in module projectprofiler.projects.views. Error was:
'module' object has no attribute 'CommaSeparatedIntegerField'
Request Method: GET
Request URL:
http://imageweb.broad.mit.edu:8081/projectprofiler/admin/projects/project/504/
Exception Type: ViewDoesNotExist
Exception Value:Tried logout_view in module
projectprofiler.projects.views. Error was: 'module' object has no
attribute 'CommaSeparatedIntegerField'
Exception Location: /imaging/analysis/People/imageweb/python-packages/
django/core/urlresolvers.py in _get_callback, line 184
...
In template /home/radon01/afraser/projectprofiler/templates/admin/
base.html, error at line 28
28{% trans 'Change password' %}

...I can't figure out what the password_change view as to do with the
commaseparatedintegerfield.

Thanks again  :]
Adam

On Mar 26, 11:39 am, Brian Neal <bgn...@gmail.com> wrote:
> On Mar 26, 9:59 am, Adam Fraser <adam.n.fra...@gmail.com> wrote:
>
> > hrm, I think I'm _finally_ starting to understand how django is meant
> > to be used.
>
> > Question: Why can't I just specify the widget used by a particular
> > field from my model in the admin interface.
>
> > stains = models.CommaSeparatedIntegerField(widget=SelectMultiple
> > (choices=STAIN_CHOICES))
>
> > ...or can I?  You suggested something like this earlier only referred
> > to forms.CommaSeparatedIntegerField rather than
> > models.CommaSeparatedIntegerField.
>
> > hrm
>
> Models are simply models. They don't really say much about forms. What
> the admin application does is to make some default choices about how
> to display your model in the admin interface. It automatically builds
> the form to edit your model using some very reasonable defaults. If
> you aren't happy with those choices, you can provide the form that the
> admin should use instead of the default one. In your form, you are
> free to use different widgets for your fields and/or provide custom
> behavior.
>
> The docs describe how to provide your own form to the admin 
> here:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#form
>
> You simply provide an attribute on your ModelAdmin called 'form', set
> equal to the form class you want the admin to use. This form class
> should inherit from ModelForm. You can then customize the widgets and
> behavior anyway you would like.
>
> ModelForms are discussed 
> here:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#topics-...
>
> Overriding the default field type for a field on a ModelForm is a bit
> further 
> down:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overrid...
>
> But before you read all that, make sure you understand forms in
> Django, in 
> general:http://docs.djangoproject.com/en/dev/topics/forms/#topics-forms-index
>
> Armed with that info, you should be able to make a custom form for the
> admin to use. Good luck.
>
> BN
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: need a multiselect list box for a static list of options

2009-03-26 Thread Adam Fraser

hrm, I think I'm _finally_ starting to understand how django is meant
to be used.

Question: Why can't I just specify the widget used by a particular
field from my model in the admin interface.

stains = models.CommaSeparatedIntegerField(widget=SelectMultiple
(choices=STAIN_CHOICES))

...or can I?  You suggested something like this earlier only referred
to forms.CommaSeparatedIntegerField rather than
models.CommaSeparatedIntegerField.

hrm

On Mar 24, 10:59 am, Brian Neal <bgn...@gmail.com> wrote:
> On Mar 24, 8:55 am, Adam Fraser <adam.n.fra...@gmail.com> wrote:
>
>
>
> > Still doesn't work.  Maybe I should be more specific.
>
> > I'm editing projectprofiler/projects/models.py which hasn't needed to
> > import forms for anything, and when I do I get very strange errors.
>
> > Here's what it looks like now:
>
> > from django.db import models
> > from django.contrib.auth.models import User
> > from projectprofiler.middleware import threadlocals
>
> > #CHOICES defined here
> > #...
>
> > class Project(models.Model):
> >     name  = models.CharField(max_length=200)
> >     complexity                  = models.PositiveIntegerField
> > (choices=COMPLEXITY_CHOICES, default=0)
> >     affiliation                 = models.PositiveIntegerField
> > (choices=AFFILIATION_CHOICES, default=0
> >     description                 = models.TextField(max_length=300,
> > blank=True) # not required
> >    ...etc
>
> > ...as you can see, everything is coming from django.db.models.  I have
> > never had to specify the actual widgets that input the data in the
> > admin pages on the site... they are just automatic.  What confuses me
> > to death is how all I need to do is add "from django import forms" to
> > the above code to make it break.
>
> > -Adam
>
> I thought you were trying to make a form. Are you trying to do all
> this from the admin?
> If that is the case you can provide your own form that the admin will
> use. In that form is where you specify the fields and widgets you
> need.
> Take a look at the forms documentation and also the model-forms docs.
--~--~-~--~~~---~--~~
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: need a multiselect list box for a static list of options

2009-03-24 Thread Adam Fraser

Still doesn't work.  Maybe I should be more specific.

I'm editing projectprofiler/projects/models.py which hasn't needed to
import forms for anything, and when I do I get very strange errors.

Here's what it looks like now:

from django.db import models
from django.contrib.auth.models import User
from projectprofiler.middleware import threadlocals

#CHOICES defined here
#...

class Project(models.Model):
name  = models.CharField(max_length=200)
complexity  = models.PositiveIntegerField
(choices=COMPLEXITY_CHOICES, default=0)
affiliation = models.PositiveIntegerField
(choices=AFFILIATION_CHOICES, default=0
description = models.TextField(max_length=300,
blank=True) # not required
   ...etc


...as you can see, everything is coming from django.db.models.  I have
never had to specify the actual widgets that input the data in the
admin pages on the site... they are just automatic.  What confuses me
to death is how all I need to do is add "from django import forms" to
the above code to make it break.

-Adam


Brian Neal wrote:
> On Mar 23, 3:36 pm, Adam Fraser <adam.n.fra...@gmail.com> wrote:
> > I found the SelectMultiple widget here:
> >
> > http://docs.djangoproject.com/en/dev/ref/forms/widgets/
> >
> > But I still don't know how to hook that up to a model like
> > CommaSeparatedIntegerField.
> >
> > help?
> >
>
> Did you try something like this? This is off the top of my head:
>
> class MyForm(forms.ModelForm):
>my_choices = forms.CommaSeparatedIntegerField
> (widget=forms.SelectMultiple(choices=STAIN_CHOICES))
>
> See:
> http://docs.djangoproject.com/en/dev/ref/forms/widgets/#specifying-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: need a multiselect list box for a static list of options

2009-03-23 Thread Adam Fraser

I found the SelectMultiple widget here:

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

But I still don't know how to hook that up to a model like
CommaSeparatedIntegerField.

help?

On Mar 23, 3:25 pm, Adam Fraser <adam.n.fra...@gmail.com> wrote:
> I don't see anything called SelectMultiple on the page you linked.
> That was the page I've been scouring for a while now looking for a way
> to do this.  The ModelMultipleChoiceField looks promising, but
> apparently it's associated with a ManyToManyField model, and that
> doesn't really fit what I'm going for, but seems to complicate things,
> requiring me to make a whole separate model class and add the
> corresponding tables and columns to my database when all I want are a
> few static choices.
>
> Thanks for taking the time to respond!
>
> Any other ideas?
> -Adam
>
> On Mar 23, 3:09 pm, Briel <toppe...@gmail.com> wrote:
>
> > Hi.
>
> > I haven't played much around with this kind of thing, but I
> > would suggest that you take a look at the form widgets.
> > One of them is called, SelectMultiple, which I bet is the one
> > you are after, but I'm not sure if it will work with choices.
> > You can find something about it 
> > athttp://docs.djangoproject.com/en/dev/topics/forms/modelforms/
>
> > ~Jakob
>
> > On 23 Mar., 19:49, Adam Fraser <adam.n.fra...@gmail.com> wrote:
>
> > > Hello,
>
> > > This should be a pretty simple question.  I have a list of options:
>
> > > STAIN_CHOICES = (
> > >     (1, 'DNA - DAPI'),
> > >     (2, 'DNA - Hoechst'),
> > >     (3, 'DNA - other'),
> > >     (4, 'Actin - Phalloidin'),
> > >     (5, 'Tubulin'),
> > > )
>
> > > I would like users to be able to select more than one of these things
> > > at a time.  It looks like models.CommaSeparatedIntegerField would be
> > > good for this, but how can I get a multi-selection list box as an
> > > input?
>
> > > -adam
--~--~-~--~~~---~--~~
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: need a multiselect list box for a static list of options

2009-03-23 Thread Adam Fraser

I don't see anything called SelectMultiple on the page you linked.
That was the page I've been scouring for a while now looking for a way
to do this.  The ModelMultipleChoiceField looks promising, but
apparently it's associated with a ManyToManyField model, and that
doesn't really fit what I'm going for, but seems to complicate things,
requiring me to make a whole separate model class and add the
corresponding tables and columns to my database when all I want are a
few static choices.

Thanks for taking the time to respond!

Any other ideas?
-Adam

On Mar 23, 3:09 pm, Briel <toppe...@gmail.com> wrote:
> Hi.
>
> I haven't played much around with this kind of thing, but I
> would suggest that you take a look at the form widgets.
> One of them is called, SelectMultiple, which I bet is the one
> you are after, but I'm not sure if it will work with choices.
> You can find something about it 
> athttp://docs.djangoproject.com/en/dev/topics/forms/modelforms/
>
> ~Jakob
>
> On 23 Mar., 19:49, Adam Fraser <adam.n.fra...@gmail.com> wrote:
>
> > Hello,
>
> > This should be a pretty simple question.  I have a list of options:
>
> > STAIN_CHOICES = (
> >     (1, 'DNA - DAPI'),
> >     (2, 'DNA - Hoechst'),
> >     (3, 'DNA - other'),
> >     (4, 'Actin - Phalloidin'),
> >     (5, 'Tubulin'),
> > )
>
> > I would like users to be able to select more than one of these things
> > at a time.  It looks like models.CommaSeparatedIntegerField would be
> > good for this, but how can I get a multi-selection list box as an
> > input?
>
> > -adam
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



need a multiselect list box for a static list of options

2009-03-23 Thread Adam Fraser

Hello,

This should be a pretty simple question.  I have a list of options:

STAIN_CHOICES = (
(1, 'DNA - DAPI'),
(2, 'DNA - Hoechst'),
(3, 'DNA - other'),
(4, 'Actin - Phalloidin'),
(5, 'Tubulin'),
)

I would like users to be able to select more than one of these things
at a time.  It looks like models.CommaSeparatedIntegerField would be
good for this, but how can I get a multi-selection list box as an
input?

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



elusive Post error

2008-07-08 Thread Adam Fraser

I was wondering if anyone else has ever run into this problem...

When filling out a form, I click submit and get a POST error claiming
that the page does not support POST.  However, if I refresh the error
page, the request goes through, and all is happy.

I don't have much experience with web applications, so I'm not sure
where to start here.  We're running on Apache and using SSL for
authentication, but I disabled SSL and the problem persists.

Here's my settings file anyway... any ideas?

-Adam


# Django settings for ProjectProfiler project.

import posix  # for getuid
import pwd# for getpwuid

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', '[EMAIL PROTECTED]'),
)

MANAGERS = ADMINS

DATABASE_ENGINE = 'mysql'# 'postgresql_psycopg2',
'postgresql', 'mysql', 'sqlite3' or 'oracle'.

# Check whether to use the test or production version of the DB
if (pwd.getpwuid(posix.getuid())[0] == "imageweb") :
DATABASE_NAME = 'projectprofiler'# Or path to database
file if using sqlite3.
else :
DATABASE_NAME = 'projectprofilertest'# Or path to database
file if using sqlite3.

DATABASE_USER = 'cpuser' # Not used with sqlite3.
DATABASE_PASSWORD = 'cPus3r' # Not used with sqlite3.
DATABASE_HOST = 'imgdb01.broad.mit.edu'  # Set to empty string for
localhost. Not used with sqlite3.
DATABASE_PORT = ''   # Set to empty string for
default. Not used with sqlite3.

TIME_ZONE = 'America/New_York'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
MEDIA_ROOT = '/home/radon01/afraser/projectprofiler/trunk/
projectprofiler/media/'
MEDIA_URL = 'http://127.0.0.1:8000/projectprofiler/media/'
ADMIN_MEDIA_PREFIX = '/projectprofiler/media/admin/'
SECRET_KEY = '&[EMAIL PROTECTED]+2(2w9fu$6=-'

TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
# 'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
#'django.contrib.auth.middleware.AuthenticationMiddleware',
'projectprofiler.sslauth.middleware.SSLAuthMiddleware',
'django.middleware.doc.XViewMiddleware',
'projectprofiler.middleware.threadlocals.ThreadLocals',
)

ROOT_URLCONF = 'projectprofiler.urls'

TEMPLATE_DIRS = (
'/home/radon01/afraser/projectprofiler/trunk/projectprofiler/
templates',
'/imaging/analysis/People/imageweb/projectprofiler/trunk/
projectprofiler/templates',
'/Users/ljosa/research/projectprofiler/projectprofiler/trunk/
projectprofiler/templates',
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
#'django.contrib.sites',
'projectprofiler.sslauth',
'projectprofiler.projects',
'django.contrib.admin',
)

AUTHENTICATION_BACKENDS = (
'projectprofiler.sslauth.backends.SSLAuthBackend',
#'django.contrib.auth.backends.ModelBackend',
)

def myusernamegen(ssl_info):
import re
return re.sub('@mit.edu', '', ssl_info.subject_email)

SSLAUTH_CREATE_USER_CALLBACK = myusernamegen
SSLAUTH_CREATE_USER = True

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



typing in django

2008-06-20 Thread Adam Fraser

In the code snip below, I am overriding the save() method of my
"Project" object so that I can record the modification to that project
by creating and saving a "ProjectModification" object.

The idea is simple, but note that I have to convert the project field
values to strings before comparing them for inequality:

   if (str(self.__dict__[field]) !=
str(old_project.__dict__[field]) ) :

The reason I am doing this is because the type of self and old_project
turn out to be different.  It seems that regardless of the actual type
of old_project, it is regarded as type 'unicode'.  Interestingly, this
isn't the case when testing this same bit of code from the "django
shell", only when testing from the django server.

My first question is: Can anyone explain this phenomenon?
My second question is: Is there a way to resolve the actual type of
old_project.__dict__[field] after loading it here
p=Project.objects.filter(id=self.id)[0]... I think this would be
preferable to comparing all values as strings.

Many thanks,
Adam


def record_project_modifications(self, old_project):
'''Creates and stores ProjectModifications that differ between
this project and old_project.'''
fields = [f.attname for f in
Project.objects.model._meta.fields]
for field in fields:
if (str(self.__dict__[field]) !=
str(old_project.__dict__[field]) ) :
pmod = ProjectModification()
pmod.user_id = 21
pmod.project = self
pmod.date= datetime.datetime.now()
pmod.field   = field
pmod.value   = self.__dict__[field]
pmod.save(pmod)

def save(self):
'''Override models.Model.save so we can call
record_project_modificationsbefore saving the model'''
p = Project.objects.filter(id=self.id)[0]
self.record_project_modifications(old_project=p)
print "saving..."
models.Model.save(self)
print "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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Implementing a new idea

2008-06-19 Thread Adam Fraser

Signalling worked out for me but it turned out to be more complex than
it needed to be.  Here are some references in case anyone is looking:

http://www.chrisdpratt.com/2008/02/16/signals-in-django-stuff-thats-not-documented-well/
http://code.djangoproject.com/wiki/Signals

In the end, I simply resolved to override the save() method of my
Project class like so:

def save(self):
record_project_modification()
models.Model.save(self)

..here's the function that saves my new ProjectModification object:

def record_project_modification(self):
pmod = ProjectModification()
pmod.user_id = 21
pmod.project = self
pmod.date = datetime.date.today()
pmod.change_field = "test"
pmod.change_from =  "test"
pmod.change_to = "test"
pmod.save(pmod)

...I would have used the method mentioned in my first ref. above, but
it turns out I couldn't have models importing signals while signals
imported models.  Otherwise it would have made more sense for me to
use signaling for scalability and elegance.

-adam

On Jun 18, 11:35 am, Adam Fraser <[EMAIL PROTECTED]> wrote:
> I didn't, but you can bet I will now.  Thanks for the lead!
> -Adam
>
> On Jun 17, 4:22 pm, Dan <[EMAIL PROTECTED]> wrote:
>
> > Did you take a look at Django Signals? You can intercept pre-save and
> > post-save objects with them. You can use that to grab the data you
> > want and fill your ProjectModification object. I don't know if there
> > is a way you could tell if it was done in the admin or not though...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Implementing a new idea

2008-06-18 Thread Adam Fraser

I didn't, but you can bet I will now.  Thanks for the lead!
-Adam

On Jun 17, 4:22 pm, Dan <[EMAIL PROTECTED]> wrote:
> Did you take a look at Django Signals? You can intercept pre-save and
> post-save objects with them. You can use that to grab the data you
> want and fill your ProjectModification object. I don't know if there
> is a way you could tell if it was done in the admin or not though...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Implementing a new idea

2008-06-17 Thread Adam Fraser

Hello,

I am currently using Django to keep track of "Timecards" submitted
towards work on different "Projects".  What I would like to do, is to
track when "Modifications" are made on projects (via the project admin
page).  (I'm quoting words that are represented literally in the data
model.)

For example: Someone logged in might want to change the "status" of a
particular project from 'assay development' to 'completed'.

What I would like to do, is create a new "ProjectModification" every
time something like this happens.

class ProjectModification(models.Model):
project = models.ForeignKey(Project)
user = models.ForeignKey(User)
date  = models.DateField()
change_field = models.CharField(max_length=200)
change_from = models.CharField(max_length=200)
change_to = models.CharField(max_length=200)

Does anyone have an idea of how I could accomplish this?

I am already using a specialized version of the 'change_form.html'
template for Projects, so modifications could be made here without
affecting other admin change_forms.

Any help would be greatly appreciated.
-Adam
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: User matching query does not exist.

2008-06-17 Thread Adam Fraser

Got it... noticed that there was a single invalid user_id in my
timecard table in the database.  Not sure how this could have
happened.

-Adam

On Jun 17, 2:43 pm, Adam Fraser <[EMAIL PROTECTED]> wrote:
> Suddenly, I am getting the following error when I try to look at my
> Timecard objects, via Timecard.objects.all()
>
> >>> Timecard.objects.all()
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/imaging/analysis/People/imageweb/python-packages/django/db/
> models/query.py", line 108, in __repr__
> return repr(self._get_data())
>   File "/imaging/analysis/People/imageweb/python-packages/django/db/
> models/base.py", line 125, in __repr__
> return smart_str(u'<%s: %s>' % (self.__class__.__name__,
> unicode(self)))
>   File "/home/radon01/afraser/projectprofiler/trunk/projectprofiler/../
> projectprofiler/projects/models.py", line 155, in __unicode__
> return "%d: %s %s" % (self.id, self.user, self.date)
>   File "/imaging/analysis/People/imageweb/python-packages/django/db/
> models/fields/related.py", line 209, in __get__
> rel_obj = self.field.rel.to._default_manager.get(**params)
>   File "/imaging/analysis/People/imageweb/python-packages/django/db/
> models/manager.py", line 69, in get
> return self.get_query_set().get(*args, **kwargs)
>   File "/imaging/analysis/People/imageweb/python-packages/django/db/
> models/query.py", line 263, in get
> raise self.model.DoesNotExist, "%s matching query does not exist."
> % self.model._meta.object_name
> DoesNotExist: User matching query does not exist.
>
> Here's my model:
> class Timecard(models.Model):
> user = models.ForeignKey(User)
> date = models.DateField()
> def __unicode__(self):
> return "%d: %s %s" % (self.id, self.user, self.date)
> class Meta:
> unique_together = (("user", "date"),)
> class Admin:
> pass
>
> Does anyone have an idea why this may suddenly be happening?  I
> noticed that the MySQL column name corresponding to
> models.ForeignKey(User), is actually "user_id"... this is correct
> though right?
>
> -Adam
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



User matching query does not exist.

2008-06-17 Thread Adam Fraser

Suddenly, I am getting the following error when I try to look at my
Timecard objects, via Timecard.objects.all()

>>> Timecard.objects.all()
Traceback (most recent call last):
  File "", line 1, in 
  File "/imaging/analysis/People/imageweb/python-packages/django/db/
models/query.py", line 108, in __repr__
return repr(self._get_data())
  File "/imaging/analysis/People/imageweb/python-packages/django/db/
models/base.py", line 125, in __repr__
return smart_str(u'<%s: %s>' % (self.__class__.__name__,
unicode(self)))
  File "/home/radon01/afraser/projectprofiler/trunk/projectprofiler/../
projectprofiler/projects/models.py", line 155, in __unicode__
return "%d: %s %s" % (self.id, self.user, self.date)
  File "/imaging/analysis/People/imageweb/python-packages/django/db/
models/fields/related.py", line 209, in __get__
rel_obj = self.field.rel.to._default_manager.get(**params)
  File "/imaging/analysis/People/imageweb/python-packages/django/db/
models/manager.py", line 69, in get
return self.get_query_set().get(*args, **kwargs)
  File "/imaging/analysis/People/imageweb/python-packages/django/db/
models/query.py", line 263, in get
raise self.model.DoesNotExist, "%s matching query does not exist."
% self.model._meta.object_name
DoesNotExist: User matching query does not exist.


Here's my model:
class Timecard(models.Model):
user = models.ForeignKey(User)
date = models.DateField()
def __unicode__(self):
return "%d: %s %s" % (self.id, self.user, self.date)
class Meta:
unique_together = (("user", "date"),)
class Admin:
pass

Does anyone have an idea why this may suddenly be happening?  I
noticed that the MySQL column name corresponding to
models.ForeignKey(User), is actually "user_id"... this is correct
though right?

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



Re: can't find media

2008-06-12 Thread Adam Fraser

Correction, winter.css is loading... just not base.css.  Turns out
this is in ./projectprofiler/meda/admin/css  That solves it.

On Jun 12, 1:36 pm, Adam Fraser <[EMAIL PROTECTED]> wrote:
> Hrm, well now the URL resolves and I can see the contents of the file
> by going 
> herehttp://127.0.0.1:8000/projectprofiler/media/projects/zapatec/winter.css
>
> ...yet the css is not loading in the actual template:
> 
>
> However, the javascript IS loading (and obviously the URL resolves as
> well),
> 
>
> Any ideas what's causing this?
>
> -Adam
>
> On Jun 12, 1:10 pm, Jeff Anderson <[EMAIL PROTECTED]> wrote:
>
> > Adam Fraser wrote:
> > > Hi,
>
> > > I'm testing Django locally and I've added the line:
> > > (r'^projectprofiler/media/(?P.*)$', 'django.views.static.serve',
> > > {'document_root': '/projectprofiler/media/'}),
> > > to urls.py as it is mentioned to do so here (http://
> > >www.djangoproject.com/documentation/static_files/).  Note: The path to
> > > the file on the site is the same as it is locally.
>
> > > The browser is now being directed to the correct place, but I'm still
> > > getting a 404 even though the path to the directory is exactly
> > > correct:
>
> > > Request URL:  http://127.0.0.1:8000/projectprofiler/media/MochiKit.js
> > > "/projectprofiler/media/MochiKit.js" does not exist
>
> > type "ls /projectprofiler/media/MochiKit.js"
>
> > I'm suspecting that "projectprofiler" isn't a directory off /
>
> > You need to supply the full path.
>
> > Jeff Anderson
>
> >  signature.asc
> > 1KDownload
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: can't find media

2008-06-12 Thread Adam Fraser

Hrm, well now the URL resolves and I can see the contents of the file
by going here 
http://127.0.0.1:8000/projectprofiler/media/projects/zapatec/winter.css

...yet the css is not loading in the actual template:


However, the javascript IS loading (and obviously the URL resolves as
well),


Any ideas what's causing this?

-Adam



On Jun 12, 1:10 pm, Jeff Anderson <[EMAIL PROTECTED]> wrote:
> Adam Fraser wrote:
> > Hi,
>
> > I'm testing Django locally and I've added the line:
> > (r'^projectprofiler/media/(?P.*)$', 'django.views.static.serve',
> > {'document_root': '/projectprofiler/media/'}),
> > to urls.py as it is mentioned to do so here (http://
> >www.djangoproject.com/documentation/static_files/).  Note: The path to
> > the file on the site is the same as it is locally.
>
> > The browser is now being directed to the correct place, but I'm still
> > getting a 404 even though the path to the directory is exactly
> > correct:
>
> > Request URL:  http://127.0.0.1:8000/projectprofiler/media/MochiKit.js
> > "/projectprofiler/media/MochiKit.js" does not exist
>
> type "ls /projectprofiler/media/MochiKit.js"
>
> I'm suspecting that "projectprofiler" isn't a directory off /
>
> You need to supply the full path.
>
> Jeff Anderson
>
>  signature.asc
> 1KDownload
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



can't find media

2008-06-12 Thread Adam Fraser

Hi,

I'm testing Django locally and I've added the line:
(r'^projectprofiler/media/(?P.*)$', 'django.views.static.serve',
{'document_root': '/projectprofiler/media/'}),
to urls.py as it is mentioned to do so here (http://
www.djangoproject.com/documentation/static_files/).  Note: The path to
the file on the site is the same as it is locally.

The browser is now being directed to the correct place, but I'm still
getting a 404 even though the path to the directory is exactly
correct:

Request URL:http://127.0.0.1:8000/projectprofiler/media/MochiKit.js
"/projectprofiler/media/MochiKit.js" does not exist

Any idea why it may not be finding this?

Any help would be much appreciated.
Adam
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



trying to modify admin

2008-06-09 Thread Adam Fraser

Hello,

I'm using Django to keep track hours spent working on "projects".  The
data model includes classes "Project" (name, description,...),
"Timecard" (user, date) , and "TimecardHours" (timecard, project,
hours).

With these models plugged in, I get a nice admin page for changing/
reviewing projects.  This includes a form for editing all of the
fields in a project (ie: name, description,...).  However, I would
like to be able to also see (not necessarily edit) 2 other things:

1: How much time was spent by each user on that project.
2: How much time was logged in each individual Timecard including that
project.

Could someone please give me an idea of what the best/easiest way to
go about this is?  Any suggestions would be much appreciated!

To give you an idea of what I had in mind.  I started modifying my
project class to have 2 new functions to give me summations of hours
by user, and hours per timecard:

def hours_per_person(self):
   '''Returns a dictionary keyed by username of how many hours each
user has worked on this project.'''
   userHours = {}
   for u in User.objects.all():
   userHours[u.username] = 0.0
   for h in TimecardHours.objects.all():
   if (h.project.id == self.id) and (h.hours > 0.0):
   for t in Timecard.objects.all():
   if h.timecard.id == t.id:
   userHours[t.user.username] += h.hours
   return userHours

def hours_per_timecard(self):
   '''Returns a dictionary keyed by "username [-mm-dd]" of how
many hours each user has worked on this project.'''
   tcHours = {}
   for t in Timecard.objects.all():
   tcHours[t.user.username+' ['+str(t.date.year)
+"-"+str(t.date.month)+"-"+str(t.date.day)+"]"] = 0.0
   for h in TimecardHours.objects.all():
   if (h.project.id == self.id) and (h.hours > 0.0):
   for t in Timecard.objects.all():
   if h.timecard.id == t.id:
   userHours[t.user.username+' ['+str(t.date.year)
+"-"+str(t.date.month)+"-"+str(t.date.day)+"]"] += h.hours
   return tcHours



...might there be a good way to use these functions to render to a
template?  I'm still quite new to Django so what might seem obvious to
others is still not quite obvious to me.

thanks much!
Adam

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