Re: Hi guyz . iam just a beginner in google app engine..plz help me "abt deleting datas from DATASTORE"

2012-11-09 Thread Kev Dwyer
muhammed riyas wrote:

> hi,
>  while trying to delete the datas from the datastore it shows the
> error...
> 
> 
> 
> 
> BadArgumentError at /employee/removeall/ Expected an instance or iterable
> of (,  'google.appengine.api.datastore_types.Key'>, );
> received   object at 0xb090aac>> (a instancemethod).  Request Method: GET  Request
> URL:
> http://localhost:9778/employee/removeall/  Exception Type:
> BadArgumentError  Exception Value: Expected an instance or iterable of
> (,  'google.appengine.api.datastore_types.Key'>, );
> received   object at 0xb090aac>> (a instancemethod).  Exception Location:
> /home/user/google_appengine/google/appengine/api/datastore.py in
> NormalizeAndTypeCheck, line 148
> 
> //in my view
> 
> from ITISMYAPP.main.models import Employeeprofile
> from google.appengine.ext import db
> def removeall(request):
> employees =Employeeprofile.all().fetch(2000)
> employeekeys = []
> for employee in employees:
> employeekeys.append(employee.key)
> db.delete(employeekeys)
> return render_to_response('main/index.html')
>
> i dont know why?
> 
> 
> 
> 
> 
Hello,

Your question isn't related to Django, so it is not suitable for this group.  
You should send questions about App Engine software to an App Engine-related 
group.

Having said that, the error message that you are getting is telling you that 
your employeekeys list does not contain keys, it contains references to the 
key method of each Employee instance in your query resultset.

You need to change the line

employeekeys.append(employee.key)

to

employeekeys.append(employee.key())

Now your list will contain the keys.

Cheers,

Kev 

-- 
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 use java script alert in view? i use form submit on post method. After sucessfull opreation in view i want alert

2012-09-16 Thread Kev Dwyer
Navnath Gadakh wrote:

> 
> 
Hello Navnath,

You can either submit the form via javascript and display the alert based on 
the response from the view, or submit the form normally and in your 
javascript code poll another view to check the result.

The first method is better, in my view.  Both methods depend on the user 
having enabled javascript in their browser.  Depending on your use case, 
this may not be a safe assumption.

Cheers,

Kev

-- 
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: CSS not appearing in production mode.

2012-06-17 Thread Kev Dwyer
Jak wrote:

> Hello All,
> 
> I am having a difficult time getting the CSS for my web app to appear when
> I turn debug mode to false. When debug mode = True all the images show up
> fine, but when I turn it to false only the html appears. What do you think
> could be happening?
> 
> 
> Thanks
> 
> Jak
> 
Hello

Assuming that you're using Django 1.3 or later, you should check your static 
files setup.  See 
https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/

Note that DEBUG=True affects how static files are served: 
https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/#static-file-
development-view

Cheers

-- 
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 Detect Current Page as Homepage?

2012-03-25 Thread Kev Dwyer
easypie wrote:

> I'm trying to check {% if homepage %} then show  {% endif %}
> 
> I'm not sure how to go about a test to check the current page if it's my
> homepage. Do I need to mess around with context processors? What's the
> usual way of doing it? And how would the {% if ... %} look like?
> 

Assuming your home is named "home" in your urls.py, you could try:

{% url home as home %}

{% if request.path == home %}{% endif %}

-- 
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 while importing URLconf 'permitprint.urls': day is out of range for month

2012-02-29 Thread Kev Dwyer
furby wrote:

> Caught it.  Haha.  What a funny bug.  From models.py:
> 
> 196 d = dt.datetime.today()
> 197 expires = d.replace(year=d.year+1)
> 
> There is no Feb. 29th, 2013.  So this breaks.  Thx for the help!
> 
> On Feb 29, 9:50 am, Tom Evans  wrote:
>> On Wed, Feb 29, 2012 at 3:33 PM, furby  wrote:
>> > The guy I built this for does not want to pay me to maintain it, so
>> > it's still on .96.  And yet when something breaks randomly he wonders
>> > why.  Debug enabled today for debugging.  There is no dev
>> > environment.  Only production for this.
>>
>> Customer is always right. Plus, job for life ;)
>>
>>
>>
>> > Here's the urlconf.  I've literally commented out every urlpattern
>> > expect the top one on line 4.  Still breaks:
>>
>> > 1 from django.conf.urls.defaults import *
>> > 2 from permitprint.app.models import *
>> > 3 urlpatterns = patterns('django.views.generic.simple',
>> > 4 (r'^/?$', 'direct_to_template', {'template': 'index.html'}),
>> > 5 """
>>
>> Hmmpf. One of the things improved since 0.96 is that error reporting
>> of this kind has improved. There is an import error coming from one of
>> the imports in the urlconf, and that is why it cannot import the
>> urlconf. Is there any date handling code in the top level of the
>> permitprint.app.models?
>>
>> Cheers
>>
>> Tom
> 
Perhaps not entirely coincidentally, Michael Foord blogged about this today:

http://www.voidspace.org.uk/python/weblog/arch_d7_2012_02_25.shtml#e1235

Cheers,

Kev

-- 
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: Help Me With This Form

2012-01-24 Thread Kev Dwyer
coded kid wrote:

> Hi guys, I’m trying to let this form display but it’s not displaying
> in my browser. When I open up the browser, only a blank page shows up.
> How can I go about it? Below are my codes:
> 



Hello,

In the template, you probably want 

{{ mobForm.as_table }}

For debugging purposes I suggest removing the authentication check until 
you're sure the form is actually rendered.

Cheers,

Kev


-- 
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.py startproject will NOT work.

2011-12-30 Thread Kev Dwyer
Chris Kavanagh wrote:

> Hi, I'm using WinXP, Python27, django 1.3.1.
> 
> When I try django-admin.py startproject mysite, I get a "Usage django-
> admin.py subcommand [options] [args]" listing of commands instead of
> starting the project in mysite folder. . .I've tried every workaround
> I've found on Google & on this site. I've put C:\Python27\Lib\site-
> packages\django\bin in my Env Variable Path, I've changed the registry
> setting HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command
> to PYDIR\\python.exe" "%1" %*. I've typed in the full path in the
> command line (python django-admin.py startproject mysite) & nothing
> works. And yes, I set it up using python setup.py install.
> 
> Any suggestions or other work arounds??? I'm at my wits end!!! Thanks
> for any help.
> 

Hello,

If you're seeing the usage message then python is able to find and execute
the django-admin.py script, but the script doesn't like the input that you
are providing.

Can you provide a paste of what you enter in the command prompt, and the
output that you receive?

Cheers,

Kev

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



Re: Best way to show/hide the logout link in a template?

2011-08-18 Thread Kev Dwyer
Andre Lopes wrote:

> Hi,
> 
> I am new to Django... I have made a logout link, but now I am in doubt
> on which the best way to show/hide this template tag:
> 
> [code]
> Logout
> [/code]
> 
> Which is the best way of show/hide this link?
> 
> Sorry if it is a basic question.
> 
> 
> Best Regards,
> 

I use

{% if user.is_authenticated %}

to condition my logout link's appearance.

See https://docs.djangoproject.com/en/1.3/topics/auth/#authentication-data-
in-templates

Cheers,

Kev

-- 
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: Nested formsets at Django 1.3

2011-07-31 Thread Kev Dwyer
Kev Dwyer wrote:

> Hello List,
> 
> I've been upgrading an old Django 1.1.x app to use Django 1.3, and am
> having a problem with nested formsets.
> 
...
> 
> 
> 
I omitted one important fact in this write-up.  In Nathan's original code, 
the lowest level formset is created like this:

TenantFormset(data=self.data,
  instance=instance,
  prefix='TENANTS_%s' % pk_value)

where instance is an instance of Building, the "parent" or container 
for tenants and self is an instance of 

class BaseBuildingFormset(BaseInlineFormSet)

which is instantiated like this:

BuildingFormset = inlineformset_factory(models.Block,
models.Building,
formset=BaseBuildingFormset,
extra=1)

I omitted to mention that to get around this I stopped passing in self.data, 
which led to the behaviour that I described in my original post.  Apologies 
if this misled anyone.

Up to Django 1.2.5, Nathan's code works fine.  However at 1.3, if self.data 
is passed to TenantFormset, it turns out to be empty and a ValidationError 
is raised because the ManagementForm information has not been supplied.  
This is the intended consequewnce of #11418, AFAICT.

Working on the assumption that self.data should contain the 
ManagementForm data I've tried populating it with said data, but 
ValidationError is still raised.

My use case is slightly simpler than Nathan's example as I just need to edit 
existing objects, so I'm going to try populating the formsets using 
querysets rather than instances.

Does anyone have any other ideas on how this might be made to work?  

Cheers,

Kev

-- 
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: upgrade Django 1.2.3 to 1.3

2011-07-31 Thread Kev Dwyer
veva...@yandex.ru wrote:

> After upgraging I entered python manage.py runserver and got error
> messages:
> File "manage.py", line 11, in 
> execute_manager(settings)
> File "c:\python26\lib\site-packages\django\core\management
> \__init__.py", line 438, in execute_manager
> utility.execute()
> File c:\python26\lib\site-packages\django\core\management
> \__init__.py", line 379, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
> File "c:\python26\lib\site-packages\django\core\management
> \__init__.py", line 261, in fetch_command
> klass=load_command_class
> module=import_module('%s.management.command.%s' % (app_name, name))
> File "c:\python26\lib\site-packages\django\utils\importlib.py, line
> 35, in import_module
> __import__(name)
> File "c:\python26\lib\site-packages\django\core\management\command
> \runserver.py",line 8, in 
> from django.core.handlers.wsgi import WSGIHandler
> File "c:\python26\lib\site-packages\django\core\handlers\wsgi.py",
> line 11, in 
> from django.dispatch import Signal
> File "c:\python26\lib\site-packages\django\dispatch\__init__.py", 
line
> 9, in 
> from django.dispatch.dispatcher import Signal, receiver
> ImportError: cannot import name receiver
> 
> Could you point to my mistake? Many thanks!
> 


See http://stackoverflow.com/questions/4883802/problem-with-django-1-3-
beta.

In your case your using Windows rather than Linux, but the same advice 
applies - remove the django folder (and any django eggs) from the 
c:\python26\lib\site-packages folder and re-install 1.3.  Or use 
virtualenv to maintain separate environments.

Cheers,

Kev

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



Nested formsets at Django 1.3

2011-07-30 Thread Kev Dwyer
Hello List,

I've been upgrading an old Django 1.1.x app to use Django 1.3, and am 
having a problem with nested formsets.

The structure of my formsets is based on the structure outline in 
Nathan Yerger's blog post http://yergler.net/blog/2009/09/27/nested-
formsets-with-django/, i.e. I have a grandparent object with a one to 
many relation to its child objects, and each of these child objects has 
a one to many relation to its children.

This worked fine in Django 1.1.x, but at 1.3 the forms in the lowest 
layer always have is_bound = False, even after being rendered and 
POSTed back to the view.  Consequently validation always fails and the 
objects that the forms represent cannot be updated.  I've reproduced 
the behaviour using the code from Nathan's blog post, so it seems that 
this approach to nesting formsets is no longer valid, or the code needs 
a tweak to work at 1.3.

Has anyone successfully used Nathan's code at 1.3, or is anyone able to 
point me towards a nested formset implementation that works at this 
release?

(Sorry about the absence of code examples - Nathan's post is much 
clearer than my code, so I'd recommend you look at that.)

Cheers,

Kev 



-- 
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: WEB SERVICE IN DJANGO USING ZSI

2010-11-27 Thread Kev Dwyer
On Sat, 27 Nov 2010 20:57:17 +0530, sami nathan wrote:

> for creating server.py from wsdl file i am using this following code i
> dont na weather its right but its not creating any file but its throwing
> error
 wsdl2py --extended --file=D;\soap\FlyppSms.wsdl
>   File "", line 1
> wsdl2py --extended --file=D;\soap\FlyppSms.wsdl
>^
> SyntaxError: unexpected character after line continuation character

1.  I think you should be executing this command from the system command 
prompt, 
not from within the python interpreter.

2.  You may need to change "D;" to "D:"

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



Re: django+modelform+Foreignkey

2010-03-07 Thread Kev Dwyer
On Sat, 06 Mar 2010 23:39:59 +0200, Arkeoloji.web.tr wrote:

> Hi all,
> I have some ModelForms.. This ModelForms based some ForeignKey included
> models. When i want to create a ModelForm I got these ForeignKey fields
> something like (in a dropdown menu) "BlaBla object". But i want to get
> in that dropdown menus something like "Linus Torvalds". I mean how can I
> show in that fields that Models name area or adress area?
> I made my ModelForm like that :
> 
> class Author(models.Model):
> name = models.ForeignKey(User)
> status = models.CharField(max_length=30)
> 
> 
> class AuthorForm(ModelForm):
> class Meta:
> model = Author
> exclude = ("status",)
> 
> --
> http://www.arkeoloji.web.tr

Hello,

Try giving your models a __unicode__ method, so that you can 
manage how they are displayed.

For example:

class Author(models.Model):
name = models.ForeignKey(User)
status = models.CharField(max_length=30)

def __unicode__(self):
return self.name

Cheers,

Kev

-- 
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: newbie - query not working!! Help please!!

2010-03-07 Thread Kev Dwyer
On Sat, 06 Mar 2010 09:52:06 -0800, uthaman wrote:

> url:
>   url(r'top25/(?P\d{1})/$', views.top25_test, name='top25_test'),
> 
> view:
> def top25_test(request, poll):
> entry = Poll.objects.filter(poll_id=poll)
> 
> model:
> class Poll(models.Model):
>   PUBLISHED_STATUS = 1
>   DARK_STATUS = 2
>   STATUS_CHOICES = (
>   (PUBLISHED_STATUS, 'Published'),
>   (DARK_STATUS, 'Dark'),
>   )
>   poll_id = models.AutoField(primary_key=True)
> 
> My problem is that this query returns nothing when I KNOW there is a
> record there!  The url I am using is "/top25/1/".  I have tried the
> django-debug-toolbar, but for some reason it does not debug the query. 
> Aargh!


Hello,

Your view doesn't seem to return anything - generally, it should to return an 
HttpResponse object.  Review part three of the Django tutorial.

Cheers,

Kev

-- 
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: Ajax request, json object, fields with instance of inherits class converted in regular string

2010-02-21 Thread Kev Dwyer
On Fri, 19 Feb 2010 07:00:36 -0800, manixor wrote:


> 
> The very big problem is, when I loop into object on template, in the
> monday field is not enymore the Day instance, but the string 1. How can
> I convert to an json object the week object, and to keep the instance of
> the inherits class, or how can I modify the ForeignField model, to point
> to another field, like name in my case and not to the pk, which is an
> integer in my case?

Hello Maxinor,

If I understand your problem correctly, I can think of two ways around this:

(1) Use the development release  (1.2, the natural keys 
(http://docs.djangoproject.com/en/dev/topics/serialization/#natural-keys)
enhancement may do what you want.
(2) Set Day.name to have primary_key=True, that way the name will be 
serialised instead of the automatically generated primary key.  As
you have already set Day.name to be unique making it the primary key 
shouldn't prove to be a problem.

Cheers,

Kev

-- 
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: Delete a data row that is inherit by another one.

2010-02-14 Thread Kev Dwyer
On Sun, 14 Feb 2010 10:24:08 -0800, manixor wrote:

> Hy, how can I check if a field is inherit by another one. If I delete
> that field, it delete cascade, the foreign data too.

Hello,

It's not clear what you mean by "field".  If you're talking about 
cascades in the database the documentation is at
http://docs.djangoproject.com/en/1.1/topics/db/queries/#deleting-objects

Cheers,

Kev

-- 
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: RequestContext and user.is_authenticated confusion

2010-02-14 Thread Kev Dwyer
On Sun, 14 Feb 2010 08:30:05 -0800, Achim Domma wrote:

> Hi Kev,
> 
> thanks for the hint. Trying different solutions I introduced indeed a
> typo. Now I can see the username and is_authenticated works as expected.
> But still curious: Is there a good reason, why I have to pass
> RequestContext each time? Whenever I'm using Django and having the
> feeling to violate DRY, there's usually a better solution. I'm quite
> surprised that it's not the case this time!?
> 
> cheers,
> Achim

Hello Achim,

I'm glad it's working for you now.

I don't know the original reason for having to use RequestContext; there 
is a hint in bug #650 that authentication wasn't thought to be a
common enough use case to justify the processing overhead of making
RequestContext available by default.

The idea of adding RequestContext to render_to_request by default was 
considered for 1.1 but special-cased, apparently because consensus could
not be reached.  Search the Django Developers list if you want the details.

All the best,

Kev


-- 
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: RequestContext and user.is_authenticated confusion

2010-02-14 Thread Kev Dwyer
On Sun, 14 Feb 2010 01:19:41 -0800, Achim Domma wrote:

> Hi,
> 
> depending on if a user is logged in or not, I want to display a "login"
> form or a "logout" button. I tried to use this code snippet:
> 
> http://docs.djangoproject.com/en/1.1/topics/auth/#id6
> 
> If I render my view using render_to_response("myTemplate.html") the user
> variable is empty. If I use
> render_to_response("myTemplate.html",context_instance=RequestContext(request))
> I get the correct user and can display the username. But
> is_authenticated still always returns false!? Any hint what I might be
> doing wrong?
> 
> According to the documentation
> "context_instance=RequestContext(request)" should only be required when
> passing a additional data dictionary to render_to_response. As passing
> data to a view and checking if the user is logged in should be something
> quite common, this sounds strange to me!?
> 
> I want to display the user information / status in my master template,
> so having to pass a RequestContext into the template from each view
> would be very tedious. Feels like I'm on a complete wrong way!?
> 
> Any hint would be very appreciated!
> 
> cheers,
> Achim

Hello Achim,

It's difficult to tell why is_authenticated returns false for you, but
assuming there aren't any typos in your template then you need to check 
that your views are working correctly, particularly that authentication
are not "lost" by forgetting to pass them to one of your views.

Passing a RequestContext to your templates is the correct way to give your 
templates access to authentication information.  It seems cumbersome
while your changing all your render_to_response calls but it doesn't
need any maintenance after that.

Cheers,

Kev

-- 
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: Reversing post_change_redirect argument in django.contrib.auth.views.password_change

2010-02-13 Thread Kev Dwyer
On Sat, 13 Feb 2010 13:22:54 +, Kev Dwyer wrote:

> Hello List,
> 

> 
> Does anyone know how I can avoid hardcoding the post_change_redirect
> argument to change_password, either in urls.py or perhaps by some
> trickery in the template or form?
> 
> Many thanks,
> 
> Kev


I've worked around this by copying the auth.views.change_password() 
function into my app's views.py and modifying it so it attempts to 
reverse() the post_change_redirect argument, thus permitting 
post_change_redirect to be a view.  The reverse() is wrapped by a 
try/except NoReverseMatch block so that if the reverse() fails the
original post_change_redirect string will be used for the redirect.

Two questions:
 - Does this seem like a sensible thing to do or am I reinventing the
wheel somehow?

 - Assuming that I'm not reinventing the wheel, does anyone think
it's worthwhile submitting this as a patch?

Cheers,

Kev

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



ModelFormSet foreign keys display

2009-12-05 Thread Kev Dwyer
Hello List,

I am having problems getting the forms within a modelformset to display 
as I wish.  I'm using 
Django 1.1 with python 2.6.

The model class is:

class Availability(DefaultColumns):

"""Record analyst availability."""

date = django.db.models.ForeignKey(WorkShift)
analyst = django.db.models.ForeignKey(Analyst)
status = django.db.models.ForeignKey(AvailabilityStatus)

(DefaultColumns inherits from django.db.models.Model)

This is the WorkShift model referenced in "date":

class WorkShift(DefaultColumns):

"""A shift as originally generated."""


rota = django.db.models.ForeignKey(WorkRota)
date = django.db.models.DateField()
shift_type = django.db.models.ForeignKey(ShiftType)

def __unicode__(self):
return u'' % (self.date, self.shift_type)

class Meta:

"""Internal class."""

ordering = ['date']

The form used by the formset looks like this:

class AvailabilityForm(django.forms.ModelForm):

"""ModelForm for Availability model."""

status = django.forms.ModelChoiceField(
queryset=rota.models.AvailabilityStatus.objects.all(),
empty_label=None,
widget=django.forms.RadioSelect)

def __init__(self, *args, **kwargs):
django.forms.ModelForm.__init__(self, *args, **kwargs)
self.logger = logging.getLogger('rota.forms.AvailabilityForm')
self.logger.debug('Initialisation complete.')

class Meta:
"""Meta class."""

model = rota.models.Availability


I want the form to display the date as a read-only field, however so far 
I 
can't make this work.  The code here outputs the date as a selectable 
ModelChoiceField.  If I declare date in the ModelForm class I always end 
up 
with the id from the WorkShift object rather than the date itself.

Can you advise how I can declare date (or do something else) to make this
work as I'd like?

Many thanks,

Kev


--

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.