Creating a link for Foreign key in Admin
Dear all, I have a model that has a foreign e.g class Foo(models.Model): bar = models.ForeignKey(Bar) class Bar(models.Model): name = models.CharField(max_length=50) This is my FooAdmin: class FooAdmin(admin.ModelAdmin): list_display = ['bar'] Now in the admin Foo's display list I want to have a link to go to bar display list. What would be the best way to do that in django? I tried to search in the doc but could not find a relevant howto on this issue. Thanks in advance for the insights. regards, -- http://blog.scrum8.com http://twitter.com/scrum8 --~--~-~--~~~---~--~~ 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: Template tag for getting CSS/scripts/images
On Sep 6, 5:51 am, Wiiboy wrote: > I'm considering making a custom template tag that returns a url to a > css file or image file. > > In your opinion, is it a waste of time? Not at all. This is a great way to remove dependencies on hard-coded locations, and makes it easy to move from development to production even if they have different image locations - just get the tag to change the url depending on the value of a flag in settings.py. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Creating a link for Foreign key in Admin
On Sep 6, 8:39 am, Joshua Partogi wrote: > Dear all, > > I have a model that has a foreign e.g > > class Foo(models.Model): > bar = models.ForeignKey(Bar) > > class Bar(models.Model): > name = models.CharField(max_length=50) > > This is my FooAdmin: > class FooAdmin(admin.ModelAdmin): > list_display = ['bar'] > > Now in the admin Foo's display list I want to have a link to go to bar > display list. What would be the best way to do that in django? I tried to > search in the doc but could not find a relevant howto on this issue. > > Thanks in advance for the insights. > > regards, > Define a custom method on the FooAdmin class which returns the HTML of a link to the Bar changelist with the relevant filter applied: def bar_link(self, obj): return 'See Bars' % obj.pk bar_link.allow_tags = True See http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django remove value from field with attrs disabled="disabled"
instead of using disabled field, I wrote a "StaticField" it's value is supplied in the general clean method, for details see http://www.djangosnippets.org/snippets/1523/ I hope this might help. On Sep 5, 7:52 pm, eli wrote: > Hi, > > I have problem with Django Forms and field with set attrs to > disabled="disabled" > > # forms.py > > class EditForm(forms.ModelForm): > > def __init__(self, *args, **kwargs): > super(EditForm, self).__init__(*args, **kwargs) > self.fields['title'].widget.attrs.update({'readonly': > 'readonly', 'disabled': 'disabled'}) > > class Meta: > model = MyModel > fields = ('title', 'tagline') > > # views.py > > form = EditForm(request.POST, instance=my_instance) > if form.is_valid(): > form.save() > > # models.py > > class MyModel(models.Model): > title = models.CharField(max_length=120, db_index=True) > tagline = models.TextField(, max_length=500, db_index=True) > > And now, Django remove values form field with attrs 'disabled': > 'disabled' ("readonly" without "disabled" works fine, but I need > disabled option in my html output). Why Django do that? > > Thanks for help. > > regards. --~--~-~--~~~---~--~~ 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: Creating a link for Foreign key in Admin
On Sun, Sep 6, 2009 at 6:20 PM, Daniel Roseman wrote: > > On Sep 6, 8:39 am, Joshua Partogi wrote: > > Dear all, > > > > I have a model that has a foreign e.g > > > > class Foo(models.Model): > > bar = models.ForeignKey(Bar) > > > > class Bar(models.Model): > > name = models.CharField(max_length=50) > > > > This is my FooAdmin: > > class FooAdmin(admin.ModelAdmin): > > list_display = ['bar'] > > > > Now in the admin Foo's display list I want to have a link to go to bar > > display list. What would be the best way to do that in django? I tried to > > search in the doc but could not find a relevant howto on this issue. > > > > Thanks in advance for the insights. > > > > regards, > > > > Define a custom method on the FooAdmin class which returns the HTML of > a link to the Bar changelist with the relevant filter applied: > >def bar_link(self, obj): >return 'See Bars' % > obj.pk >bar_link.allow_tags = True > > See > http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display > Is there any built-in method in django where we can that url without having to hardcode it? -- http://blog.scrum8.com http://twitter.com/scrum8 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
raw_id_fields in admin
When using one of these fields in Add mode you make a choice of the object from a popup window and the js returns the id into the field. It would be very useful if it also tacked the unicode (that you see whilst making the choice) corresponding to that id onto the end of the field as it does when displaying an object in Change mode. Paul Hide --~--~-~--~~~---~--~~ 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 remove value from field with attrs disabled="disabled"
Thanks for help. regards. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
auto populating primary key
Hello, This is my first post to the group and comparatively new to django. In my models, I have a primary key field. This primary key, will be used like a transaction id. I want to create it based on the data entered in the form and save it to the database by overloading the save() method. I am looking for pointers. Cheers ThinRhino -- Ships are safe in the harbour But that is not what ships are built for --~--~-~--~~~---~--~~ 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: Creating a link for Foreign key in Admin
On Sun, Sep 6, 2009 at 6:21 AM, Joshua Partogi wrote: > > On Sun, Sep 6, 2009 at 6:20 PM, Daniel Roseman wrote: > >> Define a custom method on the FooAdmin class which returns the HTML of >> a link to the Bar changelist with the relevant filter applied: >> >>def bar_link(self, obj): >>return 'See Bars' % >> obj.pk >>bar_link.allow_tags = True >> >> See >> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display >> > > Is there any built-in method in django where we can that url without having > to hardcode it? > > Yes (assuming you are using 1.1), for the base changelist url: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#reversing-admin-urls You'll still have to add on the filter value yourself. 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: raw_id_fields in admin
On Sun, Sep 6, 2009 at 7:25 AM, paulh wrote: > > When using one of these fields in Add mode you make a choice of the > object from a popup window and the js returns the id into the field. > It would be very useful if it also tacked the unicode (that you see > whilst making the choice) corresponding to that id onto the end of the > field as it does when displaying an object in Change mode. > > There's a ticket requesting this: http://code.djangoproject.com/ticket/7028 It has patches, I don't know if the latest still applies or will need updating for the current codebase. 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: Creating a link for Foreign key in Admin
On Sun, Sep 6, 2009 at 10:46 PM, Karen Tracey wrote: > On Sun, Sep 6, 2009 at 6:21 AM, Joshua Partogi > wrote: > >> >> On Sun, Sep 6, 2009 at 6:20 PM, Daniel Roseman wrote: >> >>> Define a custom method on the FooAdmin class which returns the HTML of >>> a link to the Bar changelist with the relevant filter applied: >>> >>>def bar_link(self, obj): >>>return 'See Bars' % >>> obj.pk >>>bar_link.allow_tags = True >>> >>> See >>> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display >>> >> >> Is there any built-in method in django where we can that url without >> having to hardcode it? >> >> > Yes (assuming you are using 1.1), for the base changelist url: > > > http://docs.djangoproject.com/en/dev/ref/contrib/admin/#reversing-admin-urls > > You'll still have to add on the filter value yourself. > Okay this is good enough for me. Thanks Karen. -- http://blog.scrum8.com http://twitter.com/scrum8 --~--~-~--~~~---~--~~ 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: ReST and path issues
Can you show the output of these commands below? (from django shell and from running under fastfcgi deamons) import sys print sys.executable for p in sys.path: print p On Sat, Sep 5, 2009 at 7:46 PM, TiNo wrote: > On Thu, Sep 3, 2009 at 00:38, TiNo wrote: > >> Hi, >> I am trying to set up a sort of smal CMS where the input is >> RestructuredText. The restructured text is parsed by a templatetag with the >> following code (taken from the PyCon rst project): >> >> @register.filter >> def restructuredparts(value, **overrides): >> """return the restructured text parts""" >> try: >> from docutils.core import publish_parts >> except ImportError: >> if settings.DEBUG: >> raise template.TemplateSyntaxError, "Error in {% >> restructuredtext %} filter: The Python docutils library isn't installed." >> return value >> else: >> docutils_settings = dict(getattr(settings, >> "RESTRUCTUREDTEXT_FILTER_SETTINGS", {})) >> docutils_settings.update(overrides) >> if 'halt_level' not in docutils_settings: >> docutils_settings['halt_level'] = 6 >> return publish_parts(source=value, writer_name="html4css1", >> settings_overrides=docutils_settings) >> >> >> On my local machine everything works fine, but on my deployment server it >> gives this error: >> >> [Errno 2] No such file or directory: >> '/lib/python2.5/docutils-0.5-py2.5.egg/docutils/writers/html4css1/html4css1.css' >> >> This only happens when django is running. In django shell or python shell >> everything works fine. The correct css file is located at >> /home/tinodb/lib/python2.5/docutils-0.5-py2.5.egg/docutils >> /writers/html4css1/html4css1.css >> >> There is a default docutils installed on the server (webfaction), but by >> checking in the shell the correct docutils is imported. Shell and fastfcgi >> deamons are run under the same user. >> >> Does anybody knows why my fastcgi deamon want to import a stylesheet from >> this location? >> > > Nobody any idea? > > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
QuerySet cache
QuerySet cache is usually quite great. However when you are looping through a very large result set it would be great if I could turn it off. So here the question, how do I turn off the queryset cache? --~--~-~--~~~---~--~~ 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: QuerySet cache
On Sun, Sep 6, 2009 at 10:14 AM, Thierry wrote: > > QuerySet cache is usually quite great. > However when you are looping through a very large result set it would > be great if I could turn it off. > So here the question, how do I turn off the queryset cache? > > > Just call .iterator() on the QuerySet and it will hvae it's cache disabled. 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 "Code can always be simpler than you think, but never as simple as you want" -- Me --~--~-~--~~~---~--~~ 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: raw_id_fields in admin
Thanks very much Karen, I'll keep an eye on the ticket. Paul On Sep 6, 2:00 pm, Karen Tracey wrote: > On Sun, Sep 6, 2009 at 7:25 AM, paulh wrote: > > > When using one of these fields in Add mode you make a choice of the > > object from a popup window and the js returns the id into the field. > > It would be very useful if it also tacked the unicode (that you see > > whilst making the choice) corresponding to that id onto the end of the > > field as it does when displaying an object in Change mode. > > There's a ticket requesting this: > > http://code.djangoproject.com/ticket/7028 > > It has patches, I don't know if the latest still applies or will need > updating for the current codebase. > > 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: auto populating primary key
Hi, On Sun, Sep 6, 2009 at 6:53 AM, ThinRhino wrote: > This is my first post to the group and comparatively new to django. Welcome! > In my models, I have a primary key field. This primary key, will be used > like a transaction id. > > I want to create it based on the data entered in the form and save it to the > database by overloading the save() method. > > I am looking for pointers. http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods HTH, Carlos. --~--~-~--~~~---~--~~ 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 in identifying (myself)
Hi, i'm using Django first time to actually make a web site. I have coded model for user profiles and view for users to change details in their profile. When i log in, i can see that i'm logged in at front page and i can use admin sites. But when i go to my view of changing user details, it thinks that i'm not logged in. However, if i wipe out if-tags of checking authentication, it retrieves information of my user profile to my form. # profile/models.py #!/usr/bin/python # -*- coding: latin-1 -*- from django.db import models from django.contrib.auth.models import User from django.forms import ModelForm # Create your models here. class Profiili(models.Model): kayttajanimi = models.ForeignKey(User, unique=True,verbose_name=u'Käyttäjänimi',editable=True) puhnro = models.CharField (max_length=20,verbose_name=u'Puhelinnumero') ika = models.DateField(verbose_name=u'Ikä') vapaasana = models.TextField(blank=True,verbose_name=u'Vapaa sana',help_text=u'Tähän voit esittää pelitoivomuksia yms. Mainitse myös jos koneesi virtalähde on yli 450W ja epäilet virrankulutuksesi olevan yli 350w (lähinnä vain markkinoiden tehokkaimmat koneet vievät yli 300w)') h_etunimi = models.CharField (blank=True,max_length=50,verbose_name=u'Huoltajan etunimi',help_text=u'Jos olet alle 18-vuotias, täytä myös seuraavat tiedot') h_sukunimi = models.CharField (blank=True,max_length=50,verbose_name=u'Huoltajan sukunimi') h_puh = models.CharField (max_length=20,null=True,blank=True,verbose_name=u'Huoltajan puhelinnumero') ip = models.IPAddressField(verbose_name=u'IP- osoite',editable=False,blank=True,null=True) def __unicode__(self): return self.kayttajanimi.username class Meta: verbose_name_plural = "Profiilit" verbose_name = "Profiili" class ProfiiliFormi(ModelForm): class Meta: model = Profiili # profile/views.py #!/usr/bin/python # -*- coding: latin-1 -*- from django.shortcuts import render_to_response from django.contrib.auth.models import User from monarilan.profiili.models import Profiili,ProfiiliFormi from django.forms.models import modelformset_factory from django.http import HttpResponseRedirect # Create your views here. def index(request): # Yeah, i tried to check that im authenticated at here also afterwards. Result was that it knew i was authenticated, but result was still same. So the problem is in template(?) if not request.user.is_authenticated(): return HttpResponseRedirect('/') else: profiili = Profiili.objects.get(pk=request.user.pk) UserForm = ProfiiliFormi(instance=profiili) if request.method == 'POST': formset = UserForm(request.POST, request.FILES) if formset.is_valid(): formset.save() else: return render_to_response('profiili.htm', {'form': UserForm,}) # templates/profiili.htm {% extends "index.htm" %} {% block headtitle %}Profiili{% endblock %} {% block content %} {# Don't mind about that there isn't any form-tags :p #} {{ form.as_p }} {% endblock %} If there's something missing, tell ofc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django testing applications: using fixtures
Django testing application: using fixtures Hi ! I came across strange problem while trying to use mixtures in my unittests For example, I created a fixture from the database: silver:jin oleg$ python manage.py dumpdata > datastored.json Strange, but when the fixture is loaded while the test run I see an error: Problem installing fixture './datastored.json': Traceback (most recent call last): File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/management/commands/loaddata.py", line 119, in handle obj.save() File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/serializers/base.py", line 163, in save models.Model.save_base(self.object, raw=True) File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/models/base.py", line 362, in save_base rows = manager.filter(pk=pk_val)._update(values) File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/models/query.py", line 435, in _update return query.execute_sql(None) File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/models/sql/subqueries.py", line 117, in execute_sql cursor = super(UpdateQuery, self).execute_sql(result_type) File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/models/sql/query.py", line 1734, in execute_sql cursor.execute(sql, params) File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/backends/mysql/base.py", line 83, in execute return self.cursor.execute(query, args) File "build/bdist.macosx-10.3-i386/egg/MySQLdb/cursors.py", line 166, in execute self.errorhandler(self, exc, value) File "build/bdist.macosx-10.3-i386/egg/MySQLdb/connections.py", line 35, in defaulterrorhandler raise errorclass, errorvalue IntegrityError: (1062, "Duplicate entry 'goserver-activelist' for key 'app_label'") I tried to check, why it happens, but I can't see any duplication in the json file Could you please take a look, why it happens? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
QuerySet method question
Hi everyone, I have the following three models: User, Item, User_Item, which are defined as follows def User(models.Model): id = models.CharField(primary_key=True) def Item(models.Model): id = models.CharField(primary_key=True) def User_Item(models.Model): user = models.ForeignKey(User) item = models.ForeignKey(Item) Now for example I want to find all the items that user JOHN is related to, i do User_Item.objects.filter(user='JOHN') and I get a list of User_Item objects. The question is: WHAT is the easiest way to get a list of Item objects from the list of User_Item objects, i.e., instead of returning the user-item relation, we only return the items. Thanks, -Larry --~--~-~--~~~---~--~~ 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: QuerySet method question
On Sep 6, 7:08 pm, Larry wrote: > Hi everyone, > > I have the following three models: User, Item, User_Item, which are > defined as follows > > def User(models.Model): > id = models.CharField(primary_key=True) > > def Item(models.Model): > id = models.CharField(primary_key=True) > > def User_Item(models.Model): > user = models.ForeignKey(User) > item = models.ForeignKey(Item) > > Now for example I want to find all the items that user JOHN is related > to, i do > User_Item.objects.filter(user='JOHN') > and I get a list of User_Item objects. > > The question is: WHAT is the easiest way to get a list of Item objects > from the list > of User_Item objects, i.e., instead of returning the user-item > relation, we only return > the items. > > Thanks, > -Larry Use the double-underscore syntax to traverse relations. Item.objects.filter(user_item__user='JOHN') -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: QuerySet cache
Awesome Right now im looping through the items as follows chunk_size = 1 start = 0 while True: end = start + chunk_size items= items_queryset[start:end]; start += chunk_size etc. Is there an option to specify the chunk size (actual value retrieval, not just object creation)? Cause from the docs it appears to read all data in memory and iterate the objects... http://docs.djangoproject.com/en/dev/ref/models/querysets/#iterator On Sep 6, 4:17 pm, Alex Gaynor wrote: > On Sun, Sep 6, 2009 at 10:14 AM, Thierry wrote: > > > QuerySet cache is usually quite great. > > However when you are looping through a very large result set it would > > be great if I could turn it off. > > So here the question, how do I turn off the queryset cache? > > Just call .iterator() on the QuerySet and it will hvae it's cache disabled. > > 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 > "Code can always be simpler than you think, but never as simple as you > want" -- Me --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
custom model field getting "may not be NULL" error on update
Hi all, I wrote a custom field which should get an object by a primary key value (chainId). The base storage type is an int. I have a call that does "obj.save(force_update=True)", and I get this "may not be NULL" error. I set a debug point in execute_sql(), and indeed, it seems to say "UPDATE ... fieldname = NULL, ... WHERE ...". My get_db_prep_value () looks like this: def get_db_prep_value(self, value): assert isinstance(value.chainId, (int, long)) return value.chainId If anyone has encountered a similar problem, I'd appreciate it. regards, Nicholas class ImmutableRefField(models.Field): __metaclass__ = models.SubfieldBase def __init__(self, typegetter, *argv, **kwargs): self.typegetter = typegetter models.Field.__init__(self, *argv, **kwargs) def get_internal_type(self): return "IntegerField" def to_python(self, value): if isinstance(value, (int, long, str)): clstype = self.typegetter() assert issubclass(clstype, ImmutableModel) return clstype.ReferenceGetter(clstype, value) elif isinstance(value, (ImmutableModel, ImmutableModel.ReferenceGetter)): return value raise NotImplementedError, "unknown value type %r" %(value) # dynamically typed is nice; this could be a reference or an object def get_db_prep_value(self, value): assert isinstance(value.chainId, (int, long)) return value.chainId def get_db_prep_lookup(self, lookup_type, value): if lookup_type == 'exact': return [self.get_db_prep_value(value)] pyhelp = help; import pdb; pdb.set_trace() if lookup_type == 'in': return [force_unicode(v) for v in value] if lookup_type == 'isnull': return [] raise FieldError('Invalid lookup type: %r' % lookup_type) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Basic 404.html template issue
Hi everyone, I'm struggling with an issue my girlfriend says is "ironic". I can't get my custom 404 page to show. I've broken this down to the simplest possible case. Here's what I did: Create a new project called "experiment" in /home/me/experiment and add a directory to that called templates. Here's the contents of /home/ me/experiment/experiment: __init__.py manage.py settings.py templates urls.py modify the following in settings.py: DEBUG = False TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/ django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. "/home/me/experiment/experiment/templates" ) start up the testserver and go to http://localhost:8000/osdijfosdijf and get "TemplateDoesNotExist: 500.html". OK, makes sense. Now add 500.html to the /experiment/templates directory. Contents are "500 page". revisit: http://localhost:8000/osdijfosdijf again and see "500 page" Perfect. Now the weird part. Add a "404.html" to the same templates directory and put this in it: "404 page" and again go to http://fairware:8000/sdfdf now firefox says: "Cannot Complete Request Additional information about this problem or error is currently unavailable" here's what gets spat out of the testserver when I submit the request: [06/Sep/2009 17:55:20] "GET /sdfdf HTTP/1.1" 404 9 I feel like there isn't much to be missed here, but that I must have missed it. If I create a file called "404.html" in my root template directory, shouldn't I see the contents of that file when I get a 404? Obviously django is finding the template. I'm using django 1.1 with python 2.6 on ubuntu jaunty. I've (mis?)read all of the django docs I can find on this. If anyone has incite, please share. Thank You --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django windows service
Hi, I'm looking to try and run some python code that has complete access to the django framework and some existing app models that I have in a project as a windows service. I have an app that allows a user to set up an email that should send sometime in the future. I want a windows service to be checking the mySQL database periodically for emails to send. So I've looked around the net to see what I can find and I think there is enough there for me to hack something together that works. My python experience is purely through django alone. However I wanted to see if anyone knows of some code somewhere that will help me do just this task. This particular django site runs on windows, apache + mod_python and mySQL db. - Tom --~--~-~--~~~---~--~~ 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: custom model field getting "may not be NULL" error on update
I think I found the problem: if the target object has a prepare_database_save() field, which it did (because it was a Django model object), this function will be called, replacing the target object (in subqueries.py) NOTE - "target object" means the value of the field for a model instance, which will be converted by the get_db_prep_value function. This is confusing behavior. The fix is to add a pre_save() function, def get_db_prep_value(self, value): if isinstance(value, (int, long)): return value assert isinstance(value.chainId, (int, long)) return value.chainId # NOTE - avoid Django prepare_database_save() call on value def pre_save(self, model, add): return self.get_db_prep_value(getattr(model, self.attname)) On Sep 6, 3:21 pm, gatoatigrado wrote: > Hi all, > > I wrote a custom field which should get an object by a primary key > value (chainId). The base storage type is an int. I have a call that > does "obj.save(force_update=True)", and I get this "may not be NULL" > error. I set a debug point in execute_sql(), and indeed, it seems to > say "UPDATE ... fieldname = NULL, ... WHERE ...". My get_db_prep_value > () looks like this: > > def get_db_prep_value(self, value): > assert isinstance(value.chainId, (int, long)) > return value.chainId > > If anyone has encountered a similar problem, I'd appreciate it. > > regards, > Nicholas > > class ImmutableRefField(models.Field): > __metaclass__ = models.SubfieldBase > > def __init__(self, typegetter, *argv, **kwargs): > self.typegetter = typegetter > models.Field.__init__(self, *argv, **kwargs) > > def get_internal_type(self): > return "IntegerField" > > def to_python(self, value): > if isinstance(value, (int, long, str)): > clstype = self.typegetter() > assert issubclass(clstype, ImmutableModel) > return clstype.ReferenceGetter(clstype, value) > elif isinstance(value, (ImmutableModel, > ImmutableModel.ReferenceGetter)): > return value > raise NotImplementedError, "unknown value type %r" %(value) > > # dynamically typed is nice; this could be a reference or an > object > def get_db_prep_value(self, value): > assert isinstance(value.chainId, (int, long)) > return value.chainId > > def get_db_prep_lookup(self, lookup_type, value): > if lookup_type == 'exact': > return [self.get_db_prep_value(value)] > pyhelp = help; import pdb; pdb.set_trace() > if lookup_type == 'in': > return [force_unicode(v) for v in value] > if lookup_type == 'isnull': > return [] > raise FieldError('Invalid lookup type: %r' % lookup_type) --~--~-~--~~~---~--~~ 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: Basic 404.html template issue
Have you tried this through a proper server? You've stated that your project isn't running in DEBUG but the django development server is still just that and may be causing this issue. I'm not sure but can't see any harm in seeing if you get the same result if you run through apache to see if it works. On Sep 6, 8:33 pm, moreeon wrote: > Hi everyone, I'm struggling with an issue my girlfriend says is > "ironic". I can't get my custom 404 page to show. I've broken this > down to the simplest possible case. Here's what I did: > > Create a new project called "experiment" in /home/me/experiment and > add a directory to that called templates. Here's the contents of /home/ > me/experiment/experiment: > > __init__.py > manage.py > settings.py > templates > urls.py > > modify the following in settings.py: > DEBUG = False > TEMPLATE_DIRS = ( > # Put strings here, like "/home/html/django_templates" or "C:/www/ > django/templates". > # Always use forward slashes, even on Windows. > # Don't forget to use absolute paths, not relative paths. > "/home/me/experiment/experiment/templates" > ) > > start up the testserver and go to > > http://localhost:8000/osdijfosdijf > > and get > > "TemplateDoesNotExist: 500.html". > > OK, makes sense. Now add 500.html to the /experiment/templates > directory. Contents are "500 page". > > revisit: > > http://localhost:8000/osdijfosdijf > > again and see > > "500 page" > > Perfect. Now the weird part. Add a "404.html" to the same templates > directory and put this in it: > > "404 page" > > and again go to > > http://fairware:8000/sdfdf > > now firefox says: > > "Cannot Complete Request > > Additional information about this problem or error is currently > unavailable" > > here's what gets spat out of the testserver when I submit the request: > > [06/Sep/2009 17:55:20] "GET /sdfdf HTTP/1.1" 404 9 > > I feel like there isn't much to be missed here, but that I must have > missed it. If I create a file called "404.html" in my root template > directory, shouldn't I see the contents of that file when I get a 404? > Obviously django is finding the template. > > I'm using django 1.1 with python 2.6 on ubuntu jaunty. I've (mis?)read > all of the django docs I can find on this. If anyone has incite, > please share. > > Thank You --~--~-~--~~~---~--~~ 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: Parsing / Deserializing a JSON String
On Sat, 2009-09-05 at 16:12 -0700, Eric wrote: > Thank you for your input. I tried what you suggested by first just > trying to loop through the data like so: > > " > test_output = 0 > for obj in serializers.deserialize('json', gantt_data)['ganttgroups']: > test_output = test_output + 1 > " > > This generated the following error: > > "'generator' object is unsubscriptable" > Huh. Okay. I didn't realize deserialize would return a generator. > I tried changing it slightly, moving "['ganttgroups']" inside the > brackets, to this: > > " > test_test_output = 0 > for obj in serializers.deserialize('json', gantt_data['ganttgroups']): > test_output = test_output + 1 > " > > This generated the error I originally received: > > "string indices must be integers" > Yes. Now you're trying to subscript gantt_data before you deserialize it. As you know, gantt_data is a json string. Hence the error. > I am just so new to this that I'm not sure where to go from here. Do > you have any other suggestions as to what I may be doing wrong? > Again, any help with this would be greatly appreciated. > Well, the first thing you need to do is figure out what you have to work with. You know now that deserializer returns a generator, so try looping over it to see what it yields each time around: for obj in serializers.deserialize('json', gantt_data): print '---' print type(obj) print obj That should give you a hint how to proceed. If you need more clues, then add: print dir(obj) print help(obj) That will give you some hints as to what you can do with obj. > > > > On Sep 3, 1:09 pm, "J. Cliff Dyer" wrote: > > I suspect your error is hiding in . What do you expect > > obj to be? Your JSON should return a big dictionary with one key > > ("ganttgroups"). When you iterate over a dictionary in python, you get > > the keys of that dictionary. In this case, the string "ganttgroups". > > You may be doing the following: > > > > for obj in serializers.deserialize("json", gantt_data): > > do_something_to(obj['gantts']) > > > > which returns an error, because it evaluates to "ganttgroups"['gantts'] > > (which would give you the error you see. > > > > What you want is more like: > > > > for obj in serializers.deserialize('json', gantt_data)['ganttgroups']: > > start = obj['start'] > > for gantt in obj['gantts']: > > for row in gantt['rows']: > > print row['own'] > > > > In short, you're getting your dicts and lists mixed up, or your keys and > > values. > > > > Cheers, > > Cliff > > > > On Wed, 2009-09-02 at 10:40 -0700, Eric wrote: > > > I forgot to mention that I am trying to deserialize the data as > > > follows: > > > > > " > > > ... > > > gantt_data = request.POST.get('ganttdata') > > > > > for obj in serializers.deserialize("json", gantt_data): > > > > > > ... > > > " > > > > > On Sep 2, 10:37 am, Eric wrote: > > > > Hi, > > > > I am attempting to parse a json string passed to my view via a form > > > > post. A simple example of my json structure is as follows (indented > > > > for readability): > > > > > > { > > > > "ganttgroups":[ > > > > { > > > > "gantts":[ > > > > { > > > > "rows":[ > > > > {"stt":1, "end":2, "ttl":"test row - gr1 ga1 > > > > ta1", "own":"Tim Johnson"}, > > > > {"stt":2, "end":3, "ttl":"my row (g1 t2)", > > > > "own":"John Doe"}, > > > > {"stt":1, "end":2, "ttl":"test row - gr1 ga1 > > > > ta3", "own":"Mary Smith"} > > > > ] > > > > }, > > > > { > > > > "rows":[ > > > > {"stt":1, "end":2, "ttl":"My 4th task", > > > > "own":"Eric Johnson"}, > > > > {"stt":1, "end":2, "ttl":"my row (g2 t2)", > > > > "own":"Jeff Smith"}, > > > > {"stt":1, "end":2, "ttl":"test row - gr1 ga2 > > > > t3", "own":"Bill Baker"} > > > > ] > > > > } > > > > ], > > > > "start":"2009-1-01" > > > > } > > > > ,{ > > > > "gantts":[ > > > > { > > > > "rows":[ > > > > {"stt":1, "end":2, "ttl":"row - gr2 ga1 t1", > > > > "own":"Ted Tillman"}, > > > > {"stt":1, "end":2, "ttl":"row - gr2 ga1 t2", > > > > "own":"Kim Crane"}, > > > > {"stt":1, "end":2, "ttl":"row - gr2 ga1 t3", > > > > "own":"Bob Barker"} > > > > ] > > > > } > > > > ], > > > > "start":"2009-1-01" > > > > } > > > > ] > > > > > > } > > > > > > I would like to parse it so that I can loop over the pairs/arrays to > > > > access the data. When I try to deserialize the data, I get the django > > > > error "string indices must be integers". Can anybo
Django Comments
Well, thanks to a old post on DjangoBot, I've got the new Django Comments framework installed w/o breaking my urls.py (had to go into django.contrib.comments & delete the "url" directory-- was that mentioned in any of the "migrating to 1.0" docs?) Now I'd like to test it out by simply having it send an e-mail when a comment is submitted. Won't be publishing any of the comments until we see what kind of spamload we might be expecting from the emails. The docs (http://docs.djangoproject.com/en/dev/ref/contrib/comments/ moderation/) say: email_notification¶ If True, any new comment on an object of this model which survives moderation (i.e., is not deleted) will generate an email to site staff. Default value is False. Okay, great. Can't find anything about where one might set what e- mail address this notification would get sent to. Tracing around in the code, looks like they might automatically go to any users listed as Admins...? Is there an easy way to control/limit who gets these notifications, is pretty much the short & long of what I'm asking. As always, pardon my broad ignorance-- users/user authentication et al. is a great unexplored continent for yrs truly --~--~-~--~~~---~--~~ 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: Having real problems with CSS
Karen, Thanks. You're awesome. Andrew On Sep 2, 8:52 pm, Karen Tracey wrote: > On Wed, Sep 2, 2009 at 7:53 AM, Ozymandias wrote: > > > Karen, > > > Thank you. I will give that a shot a little later this afternoon. > > > The MEDIA_ROOT change really does break the sites CSS though. Not > > sure why. > > > Was I doing the changes correctly if I were going to be hosting this > > on an actual server? I'd need to change the MEDIA_ROOT in order to > > get that to work, right? > > No, serving the admin media files has no dependence on MEDIA_ROOT. > ADMIN_MEDIA_PREFIX, yes, MEDIA_ROOT, no. Thus my surprise at your saying > changing MEDIA_ROOT affects serving admin media files. I don't understand > how that can be. > > Admin media files are static files, and Django isn't (generally) used to > serve static files. The development server automagically serves the admin > media files (keying off the value of ADMIN_MEDIA_PREFIX) from the source > tree for Django, unless you tell it otherwise. For real deployment, you > would set up your real web server to serve the files that match the > ADMIN_MEDIA_PREFIX from wherever you have (or place) the admin media files. > The mod_python doc mentions this: > > http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#id3 > > The mod_wsgi doc doesn't mention serving the admin media files specifically > but does mention how to set things up for serving static files in general. > > (I anticipate the next question is what MEDIA_ROOT is needed for at all if > Django doesn't serve static files. It's used as a base directory for where > to place uploaded files: > > http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.mod... > > I anticipate the next question being why the name MEDIA_ROOT...that I have > no idea of the answer to.) > > 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: regex problem in urls.py in Django 1.1/mod_wsgi
My noob error: I had extra "portal/" on my regex. Sorry and thanks for your attention. --~--~-~--~~~---~--~~ 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 to replace Django User class
I've look all over docs and Google to find a way to do this with no real luck. I'm using a legacy PostGreSQL database which already has user and permissions tables defined, and I don't want to have to create parallel Django User tables. It seems simple that I should just be able to completely replace the User model, but it's not. I've tried many ways of doing this to no avail. I think I probably have to completely clone Django code in my project but I'm not sure which pieces I have to have. Any help would be appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django for windows XP
Hi, I am not able to locate a Django package to be downloaded for Windows XP. Can anyone please help me in this endeavour? --vaidya --~--~-~--~~~---~--~~ 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 for windows XP
On Sep 7, 5:30 am, vaidyanathan venkataraman wrote: > Hi, > > I am not able to locate a Django package to be downloaded for > Windows XP. > > Can anyone please help me in this endeavour? > > --vaidya You don't need one - Django doesn't include any operating system specific code. Just follow the normal download instructions (http:// www.djangoproject.com/download/) or check out from the subversion repository. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django windows service
On Sep 6, 9:16 pm, cootetom wrote: > Hi, > > I'm looking to try and run some python code that has complete access > to the django framework and some existing app models that I have in a > project as a windows service. I have an app that allows a user to set > up an email that should send sometime in the future. I want a windows > service to be checking the mySQL database periodically for emails to > send. > > So I've looked around the net to see what I can find and I think there > is enough there for me to hack something together that works. My > python experience is purely through django alone. However I wanted to > see if anyone knows of some code somewhere that will help me do just > this task. This particular django site runs on windows, apache + > mod_python and mySQL db. > > - Tom The easiest way to do this sort of thing is to write a custom manage.py command - see the (unfortunately very sparse) documentation here: http://docs.djangoproject.com/en/dev/howto/custom-management-commands/ You can then set the Windows scheduler to run 'python manage.py yourcommand'. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---