Using a manipulator with ModelForms
Whilst I appreciate that hidden fields can be less than ideal in some cases I want to set default values in a form generated from a model. http://code.djangoproject.com/wiki/CookBookManipulatorWithHiddenFields gives some guidance but this approach appears to be deprecated in django 1.02 (and the refernced cookbook pages does not say so) What is the new way to do this pls? Thx. Paul class Note(models.Model): organisation = models.ForeignKey(Organisation) contact = models.ForeignKey(Contact) last_contact = models.DateTimeField() notes = models.TextField(blank=True) def __str__(self): return '%s %s' %(self.last_contact,self.contact) class NoteForm (ModelForm): class Meta: model=Note ## deprecated ### class NoteManipulator(Note.AddManipulator): def __init__(self): # Set everything up initially using the built in manipulator Note.AddManipulator.__init__(self) newFields = [] # replacing some fields with HiddenFields for field in self.fields: if field.field_name in ('user',): field = formfields.HiddenField(field.field_name, field.is_required, field.validator_list) newFields.append(field) self.fields = newFields def note(request,id=''): if request.method == "POST": .. processing stuff here .. else: oid=request.GET.get('oid','') if id: # prepare for update inst=Note.objects.get(id=id) form=NoteForm(instance=inst) submit="Update" else: # prepare for insert # default foreign key on new record manipulator = noteManipulator() dflt={'organisation=oid': oid} errors={} ### deprecated form=NoteForm().FormWrapper(manipulator, dflt, errors) submit="Insert" return render_to_response('crm/note.html',{ 'form': form, 'id': id, 'oid': oid, 'submit': submit, }) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Problem with passing information from related model to a view
As you can see from this I am just learning django. I am trying to list contacts and their related organisations. This does list the contact names. No errors are raised but fields from Organisations do not show with this view and template. I guess I need to be more explicit in referncing the related fields but have not found out how, despite looking through tutorials. Any help appreciated. Paul models.py from django.db import models class Contact(models.Model): fname = models.CharField(max_length=40) sname = models.CharField(max_length=40) email = models.CharField(max_length=60) dir_tel = models.CharField(max_length=25,blank=True) mobile = models.CharField(max_length=25,blank=True) blog = models.URLField(max_length=80,blank=True) linkedin = models.CharField(max_length=40,blank=True) def __str__(self): return '%s %s' %(self.fname,self.sname) class Organisation(models.Model): organisation = models.CharField(max_length=60) addr1 = models.CharField(max_length=40,blank=True) addr2 = models.CharField(max_length=40,blank=True) city = models.CharField(max_length=40,blank=True) county = models.CharField(max_length=40,blank=True) pcode = models.CharField(max_length=12,blank=True) def __str__(self): return '%s' %(self.organisation) views.py from models import Contact def contact_list(request): # where: .filter(fn="value") contact_list=list(Contact.objects.all().select_related()) return render_to_response('contact_list.html',{ 'contact_list': contact_list, }) contact_list.html {% block content %} {% for obj in contact_list %} {{ obj.fname }} {{ obj.sname }} : {{ obj.organisation }} {% endfor %} {% endblock %} --~--~-~--~~~---~--~~ 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: Installing django admin on apache/ mod_python
Checked two more things: - to mke sure that mod_python could compile anything it wanted to I chown'd the python distribution to apache (the user). This had and effect - various pyc files created - however, the admin app still doesn't run. - put in a symbolic link so the django distribution is visible within the mysite folder. not sure if I did this correctly and the documentation at http://docs.djangoproject.com/en/dev/howto/deployment/modpython/ doesn't clarify this. Again, this had no effect. I'd like to understand what happens when django tries to start admin. It will be looking for admin.site.root but where does it expect that to be? Also, as there is nothing in apache's error log, is there anywhere else where evidence could be found? On Dec 21, 9:31 am, paultanner <p...@virtual-techno.com> wrote: > No more input on this for a while so I tried various moving the > directories around. > My supposition is that it can't find the part of the distribution > containing theadmincode. > > vhost.conf (on a subdomain) > --- > > SetHandler python-program > PythonHandler django.core.handlers.modpython > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > PythonPath "['/var/www/test','/var/www/test/django'] + sys.path" > PythonDebug On > > > urls.py > > from django.conf.urls.defaults import * > from django.contrib importadmin > from mysite.views import current_datetimeadmin.autodiscover() > > urlpatterns = patterns('', > (r'^admin/(.*)',admin.site.root), > (r'^time/$', current_datetime), > ) > > mysite directory is at /var/www/test > django distribution is in the same place > > Is the problem with the PythonPath as: > > /time app in myuysite runs OK > /foo gives a 404 error via django debug > /adminjust hangs (blank browser - nothing appears on apache error > log.) > > Any suggestions pls? > > Paul > > On Nov 18, 12:08 pm, "Karen Tracey" <kmtra...@gmail.com> wrote: > > > > > On Tue, Nov 18, 2008 at 3:39 AM, paultanner <p...@virtual-techno.com> wrote: > > > > I got a fresh distribution (1.01) and installed it on RHEL4 linux/ > > > apache/mod_python(in a subdomain) > > > python is 2.3.4 > > > the trivial app /tim (from the book) works OK so most of the config > > > must be right > > > then tried to add theadmininterface, modifying settings.py and .. > > > > urls.py > > > --- > > > > from django.conf.urls.defaults import * > > > from django.contrib importadmin > > > from mysite.views import current_datetime > > >admin.autodiscover() > > > > urlpatterns = patterns('', > > > (r'^admin/(.*)',admin.site.root), > > > (r'^time/$', current_datetime), > > > ) > > > > This just hangs. Does not throw an error. An entry in the access_log > > > shows that it tried to redirect. > > > A cut-n-paste of what you're seeing the the log might be enlightening. > > > The other urlpattern you find is old, and will not work with 1.0.x > > > Karen- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ 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: Installing django admin on apache/ mod_python
No more input on this for a while so I tried various moving the directories around. My supposition is that it can't find the part of the distribution containing the admin code. vhost.conf (on a subdomain) --- SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonPath "['/var/www/test','/var/www/test/django'] + sys.path" PythonDebug On urls.py from django.conf.urls.defaults import * from django.contrib import admin from mysite.views import current_datetime admin.autodiscover() urlpatterns = patterns('', (r'^admin/(.*)', admin.site.root), (r'^time/$', current_datetime), ) mysite directory is at /var/www/test django distribution is in the same place Is the problem with the PythonPath as: /time app in myuysite runs OK /foo gives a 404 error via django debug /admin just hangs (blank browser - nothing appears on apache error log.) Any suggestions pls? Paul On Nov 18, 12:08 pm, "Karen Tracey" <kmtra...@gmail.com> wrote: > On Tue, Nov 18, 2008 at 3:39 AM, paultanner <p...@virtual-techno.com> wrote: > > > I got a fresh distribution (1.01) and installed it on RHEL4 linux/ > > apache/mod_python (in a subdomain) > > python is 2.3.4 > > the trivial app /tim (from the book) works OK so most of the config > > must be right > > then tried to add the admin interface, modifying settings.py and .. > > > urls.py > > --- > > > from django.conf.urls.defaults import * > > from django.contrib import admin > > from mysite.views import current_datetime > > admin.autodiscover() > > > urlpatterns = patterns('', > > (r'^admin/(.*)', admin.site.root), > > (r'^time/$', current_datetime), > > ) > > > This just hangs. Does not throw an error. An entry in the access_log > > shows that it tried to redirect. > > A cut-n-paste of what you're seeing the the log might be enlightening. > > The other urlpattern you find is old, and will not work with 1.0.x > > Karen- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ 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: Installing django admin on apache/ mod_python
Thx for confirming how to invoke admin - I checked that's how it's configured. The apache logs dont show you much. You always get a redirect [18/Nov/2008:20:07:52 +] "GET /admin HTTP/1.1" 301 - "-" "Mozilla/ 4.0 (compatible; etc" With the /time test you also get a 200 [18/Nov/2008:20:09:39 +] "GET /time/ HTTP/1.1" 200 59 "-" "Mozilla/ 4.0 (compatible; etc" This suggests that the redirect fails for /admin I'm wondering if this is a file missing or file protection problem? Any further suggestions? Paul On Nov 18, 12:08 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Tue, Nov 18, 2008 at 3:39 AM, paultanner <[EMAIL PROTECTED]> wrote: > > > I got a fresh distribution (1.01) and installed it on RHEL4 linux/ > > apache/mod_python (in a subdomain) > > python is 2.3.4 > > the trivial app /tim (from the book) works OK so most of the config > > must be right > > then tried to add the admin interface, modifying settings.py and .. > > > urls.py > > --- > > > from django.conf.urls.defaults import * > > from django.contrib import admin > > from mysite.views import current_datetime > > admin.autodiscover() > > > urlpatterns = patterns('', > > (r'^admin/(.*)', admin.site.root), > > (r'^time/$', current_datetime), > > ) > > > This just hangs. Does not throw an error. An entry in the access_log > > shows that it tried to redirect. > > A cut-n-paste of what you're seeing the the log might be enlightening. > > The other urlpattern you find is old, and will not work with 1.0.x > > Karen- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Installing django admin on apache/ mod_python
I got a fresh distribution (1.01) and installed it on RHEL4 linux/ apache/mod_python (in a subdomain) python is 2.3.4 the trivial app /tim (from the book) works OK so most of the config must be right then tried to add the admin interface, modifying settings.py and .. urls.py --- from django.conf.urls.defaults import * from django.contrib import admin from mysite.views import current_datetime admin.autodiscover() urlpatterns = patterns('', (r'^admin/(.*)', admin.site.root), (r'^time/$', current_datetime), ) This just hangs. Does not throw an error. An entry in the access_log shows that it tried to redirect. Then saw (in the book) another way to do it urlpatterns = patterns('', (r'^admin/(.*)', include('django.contrib.admin.urls')), (r'^time/$', current_datetime), ) This throws an error .. File "/usr/lib/python2.3/site-packages/django/core/urlresolvers.py", line 198, in _get_urlconf_module self._urlconf_module = __import__(self.urlconf_name, {}, {}, ['']) ImportError: No module named urls It appears that the first way mentioned is correct now. Any sugegstions as to why the redirect fails? Thx. Paul --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---