Form.clean() and custom error handling
All, I had previously been using a bit of a hack (thought I found examples of this on the mailing list, but can't find any evidence now) so that I could actually associated field specific errors with the actual field instead of having everything stuffed into __all__ / non_field_errors. The hack went something like this: class MyForm(forms.Form): field_A = forms.SomeField() # many other fields etc. field_Z = forms.SomeField(required=False) # not required in isolation, but required if field_A... def clean(self): if 'field_A' in self.cleaned_data and 'field_Z' not in self.cleaned_data: self.errors['field_Z'] = forms.util.ErrorList([u"Field Z is required if-and-only-if Field A has input, and passes validation"]) return self.cleaned_data I have a very long complicated form with many interrelated fields, so it helps to have the errors physically near the fields that need attention, rather than just say at the top "These 5 field names had errors, now go find the fields!" (I wish the form were more sane, but I have no control over this, I just have to deal as best I can). Obviously the first step is to stop using the hack, but without any concrete examples in the official documentation[1], it's not easy to figure out the 'best practices' here. Ideally, I should be able to raise/add field specific error messages in the Form.clean() method (not entirely sure what the utility of __all__ is, but everyone has their own use cases). Another issue, what if I also need to check that field_K is present if field_J is? At the `clean_field_K` level the answer is to `raise forms.ValidationError`, but I can't exactly `raise forms.ValidationError` errors twice in the same Form.clean() method and expect both of these errors to be returned can I? Thanks, John-Scott [1] http://www.djangoproject.com/documentation/forms/#custom-form-and-field-validation --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Django 1.7: How to migrate data between two external apps
Say I decided to switch from a third party app foo-tags to app bar-tags. Their Tag models are mostly identical so I just need to move the data from foo-tag to bar-tag. Since I don't control their migrations, I'd need to create a migration in one of my own apps: ./manage.py makemigrations my_app --empty In this migration I'd need to explicitly list the dependencies on these external apps (otherwise was getting errors that the foo and bar apps were not available in the app registry): # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations def migrate_tags(apps, schema_editor): FooTag = apps.get_model('foo_tag', 'FooTag') BarTag = apps.get_model('bar_tag', 'BarTag') for old_tag in FooTag.objects.all(): new_tag = BarTag.objects.create(name=old_tag.name) class Migration(migrations.Migration): dependencies = [ ('my_app', '0001_initial'), ('foo_tag', '0001_initial'), ('bar_tag', '0001_initial'), ] operations = [ migrations.RunPython(migrate_tags) ] The migration itself works as expected. However if I now remove foo_tag from INSTALLED_APPS, Django will now give an error: KeyError: "Migration my_app.0002_auto_20141212_1951 dependencies reference nonexistent parent node ('foo_tag', '0001_initial')" What's the correct way to handle migrating data between 3rd party apps where one of the apps is eventually removed? Thanks, John-Scott -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d60b5693-408f-4ce4-8219-70d1e6c48f51%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Django 1.7: How to migrate data between two external apps
My 'solution' was very smelly: - created the migration in 'my_app' as mentioned in my previous post - pushed this change to production to run - removed 'foo_tag' from INSTALLED_APPS *AND* deleted the migration file (which meant also manually deleting the history of this migration from the django_migrations table). It was hard to hold my nose through this experience but it worked. Would be great to have a general solution that could be shared with others but in the meantime, I'll settle for being able to get on with the rest of my life. On Tuesday, December 16, 2014 9:05:35 AM UTC-5, Markus Holtermann wrote: > > Hey John-Scott, > > I'm afraid but I don't see an obvious solution. There are 2 ways you could > work on the issue, I don't like either: > > 1. remove all references to the "foo_tag" app from all migration files > > 2. make use of the MIGRATION_MODULES settings: > > 2.1. create a package "path.to.foo_tag_legacy" > 2.2. inside create an empty migration "0001_initial" > 2.3. define MIGRATION_MODULES={"foo_tag": "path.to.foo_tag_legacy"} > > As said, both seem ugly to me. I don't know which way I'd proceed. > > You might get it working by squashing migrations, but certainly not > without manually writing those migration files. > > /Markus > > On Saturday, December 13, 2014 6:26:17 PM UTC+1, John-Scott wrote: >> >> Say I decided to switch from a third party app foo-tags to app bar-tags. >> Their Tag models are mostly identical so I just need to move the data from >> foo-tag to bar-tag. Since I don't control their migrations, I'd need to >> create a migration in one of my own apps: >> >> ./manage.py makemigrations my_app --empty >> >> In this migration I'd need to explicitly list the dependencies on these >> external apps (otherwise was getting errors that the foo and bar apps were >> not available in the app registry): >> >> # -*- coding: utf-8 -*- >> from __future__ import unicode_literals >> >> from django.db import models, migrations >> >> def migrate_tags(apps, schema_editor): >> FooTag = apps.get_model('foo_tag', 'FooTag') >> BarTag = apps.get_model('bar_tag', 'BarTag') >> for old_tag in FooTag.objects.all(): >> new_tag = BarTag.objects.create(name=old_tag.name) >> >> class Migration(migrations.Migration): >> dependencies = [ >> ('my_app', '0001_initial'), >> ('foo_tag', '0001_initial'), >> ('bar_tag', '0001_initial'), >> ] >> >> operations = [ >> migrations.RunPython(migrate_tags) >> ] >> >> >> The migration itself works as expected. However if I now remove foo_tag >> from INSTALLED_APPS, Django will now give an error: >> >> KeyError: "Migration my_app.0002_auto_20141212_1951 dependencies >> reference nonexistent parent node ('foo_tag', '0001_initial')" >> >> What's the correct way to handle migrating data between 3rd party apps >> where one of the apps is eventually removed? >> >> Thanks, >> John-Scott >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/97020def-7278-4416-92a2-9088455b4ff6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Django 1.7: How to migrate data between two external apps
Thanks for your replies Markus! I've added a ticket here https://code.djangoproject.com/ticket/24016 On Wednesday, December 17, 2014 10:47:26 AM UTC-5, Markus Holtermann wrote: > > I agree, a general "here's how you should do it" section in the docs > should be added. Would you mind opening a ticket on > https://code.djangoproject.com/ where you state the problem (e.g. link to > this discussion). Thanks. > > /Markus > > On Wednesday, December 17, 2014 6:01:05 AM UTC+1, John-Scott wrote: >> >> My 'solution' was very smelly: >> >>- created the migration in 'my_app' as mentioned in my previous post >>- pushed this change to production to run >>- removed 'foo_tag' from INSTALLED_APPS *AND* deleted the migration >>file (which meant also manually deleting the history of this migration >> from >>the django_migrations table). >> >> It was hard to hold my nose through this experience but it worked. Would >> be great to have a general solution that could be shared with others but in >> the meantime, I'll settle for being able to get on with the rest of my life. >> >> On Tuesday, December 16, 2014 9:05:35 AM UTC-5, Markus Holtermann wrote: >>> >>> Hey John-Scott, >>> >>> I'm afraid but I don't see an obvious solution. There are 2 ways you >>> could work on the issue, I don't like either: >>> >>> 1. remove all references to the "foo_tag" app from all migration files >>> >>> 2. make use of the MIGRATION_MODULES settings: >>> >>> 2.1. create a package "path.to.foo_tag_legacy" >>> 2.2. inside create an empty migration "0001_initial" >>> 2.3. define MIGRATION_MODULES={"foo_tag": "path.to.foo_tag_legacy"} >>> >>> As said, both seem ugly to me. I don't know which way I'd proceed. >>> >>> You might get it working by squashing migrations, but certainly not >>> without manually writing those migration files. >>> >>> /Markus >>> >>> On Saturday, December 13, 2014 6:26:17 PM UTC+1, John-Scott wrote: >>>> >>>> Say I decided to switch from a third party app foo-tags to app >>>> bar-tags. Their Tag models are mostly identical so I just need to move the >>>> data from foo-tag to bar-tag. Since I don't control their migrations, I'd >>>> need to create a migration in one of my own apps: >>>> >>>> ./manage.py makemigrations my_app --empty >>>> >>>> In this migration I'd need to explicitly list the dependencies on these >>>> external apps (otherwise was getting errors that the foo and bar apps were >>>> not available in the app registry): >>>> >>>> # -*- coding: utf-8 -*- >>>> from __future__ import unicode_literals >>>> >>>> from django.db import models, migrations >>>> >>>> def migrate_tags(apps, schema_editor): >>>> FooTag = apps.get_model('foo_tag', 'FooTag') >>>> BarTag = apps.get_model('bar_tag', 'BarTag') >>>> for old_tag in FooTag.objects.all(): >>>> new_tag = BarTag.objects.create(name=old_tag.name) >>>> >>>> class Migration(migrations.Migration): >>>> dependencies = [ >>>> ('my_app', '0001_initial'), >>>> ('foo_tag', '0001_initial'), >>>> ('bar_tag', '0001_initial'), >>>> ] >>>> >>>> operations = [ >>>> migrations.RunPython(migrate_tags) >>>> ] >>>> >>>> >>>> The migration itself works as expected. However if I now remove foo_tag >>>> from INSTALLED_APPS, Django will now give an error: >>>> >>>> KeyError: "Migration my_app.0002_auto_20141212_1951 dependencies >>>> reference nonexistent parent node ('foo_tag', '0001_initial')" >>>> >>>> What's the correct way to handle migrating data between 3rd party apps >>>> where one of the apps is eventually removed? >>>> >>>> Thanks, >>>> John-Scott >>>> >>> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9ac3c6c9-b36b-450a-9527-687623c1165c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
What happened to django-updates?
There hasn't been any updates on the django-updates mailing list since March 18. At the time, someone on IRC said they thought it was due to the traffic from the sprint but that was a month ago. I am tracking trunk with my projects and it was really convenient to get email updates on trunk commits (with handy gmail filters to trim out all the non-commit noise). I can accomplish the same thing via http://trac.tripology.com/tripology-trac/timeline?changeset=on&max=50&daysback=90&format=rss but just wanted to bring it to the attention of whoever is in charge. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: What happened to django-updates?
On Apr 14, 11:45 am, "James Bennett" <[EMAIL PROTECTED]> wrote: > On Mon, Apr 14, 2008 at 10:43 AM, John-Scott > > <[EMAIL PROTECTED]> wrote: > > There hasn't been any updates on the django-updates mailing list since > > March 18. At the time, someone on IRC said they thought it was due to > > the traffic from the sprint but that was a month ago. I am tracking > > trunk with my projects and it was really convenient to get email > > updates on trunk commits (with handy gmail filters to trim out all the > > non-commit noise). I can accomplish the same thing via > > http://trac.tripology.com/tripology-trac/timeline?changeset=on&max=50... > > but just wanted to bring it to the attention of whoever is in charge. > > "Whoever is in charge" would be the developers who write and maintain > Google's mailing-list systems. It is not a problem that anyone > associated with Django can fix. Pardon my ignorance. I lack a priori knowledge about how the Django Trac instance has been configured or whatever hook script is set up to automate sending mail to the list to know that there couldn't possibly be any problem with this configuration. I thought that the error would most likely be on that end of things and not on the Google end of things, since Groups seems to work just fine for all the other lists (django-users, django-developers, etc.). You know differently, so thanks for clearing that up. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can I prepopulate a SlugField with a ForeignKey?
It's been a while since I've used Django (trying to get back into it), but unless the API has changed dramatically since then, you should be able to do something like: def __str__(self): return 'Color: %s, Size: %s, Price: %s' % (self.color, self.size, self.price) Of course, change the string to suit your own tastes. I had a Person class and wanted to have them displayed like "last name, first name" if both names were filled in, but leave out the comma if I only had a last name. So I did: def __str__(self): if self.first_name: return '%s, %s' % (self.last_name, self.first_name) else: return self.last_name Sorry, I haven't yet used SlugField or the 'prepopulate_from' shortcut, so I don't have any advice on your troubles there. Good luck, John-Scott Atlakson On May 21, 12:01 am, Greg <[EMAIL PROTECTED]> wrote: > I have the following model > > class sdetails(models.Model): > color = models.ForeignKey(color) > size = models.ForeignKey(size) > price = models.ForeignKey(price) > theslug = models.SlugField(prepopulate_from=("color", "size", > "price")) > > class Admin: > pass > > def __str__(self,): > return str(self.size) > > However, when I add a new entry and I select a value for each > ForeignKeys the SlugField doesn't get populated. The reason why I > want this is because I don't know how to return multiple fields. > Right now I have 'return str(self.size)'. Is there a way that I can > return color, size, and and price. For example I would like to have > something like 'return str(self.color, self.size, self.price)'. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ubuntu 6.06 deployment issues
Hello all, I'm having some issues getting a basic django project in production mode. I'm using Ubuntu 6.06 LTS with the default versions of apache, python, mod_python, etc. - I've checked out the development version of Django in my home directory, i.e. /home/john-scott/workspace/django_src and I've symlinked it to /usr/lib/python2.4/site-packages/django as per the official installation instructions. - I've created a Django project in /home/john-scott/workspace/mysite following the tutorials exactly. The official documentation suggests keeping the django app code outside of /var/www for security purposes and to instead keep the code in a user directory (the specific example is '/home/mycode'). Everything works great with the development server. However, I've encountered nothing but problems trying to go 'live'. I'm using the following virtual host configuration, which again is modeled after the official docs: ServerNamemysite.com #obviously not the real url ;) SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonDebug On With this setup I get the following error: ImportError: No module named django In another thread (http://groups.google.com/group/django-users/ browse_thread/thread/e44569d185e36284/) someone said there were permission problems but their solution was to place the django_src in / opt and change the symlink accordingly. If I follow this, then the first problem goes away but then I get the following error: EnvironmentError: Could not import settings 'mysite.settings' (Is it on sys.path? Does it have syntax errors?): No module named mysite.settings In the same thread the user also put the projects in /opt as well. The real problem seems to be the Apache configuration, so I'm not convinced the answer is to throw everything in /opt, especially since none of the official docs suggest to do such a thing (IIRC the user in that thread didn't have control over apache, so they had to be creative). I've followed all the official docs quite literally. Is the suggestion in the docs to keep your projects in /home/username incorrect? Or is there something about the Apache configuration in Ubuntu 6.06 that makes deployment a wee bit more complicated than the docs suggest? If so, should the official deployment guides have a note about these gotchas? Once I get this ironed out in a sane way I'd be happy to add a write-up to the SeverArrangements wiki page. Thanks, John-Scott --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ubuntu 6.06 deployment issues
Thanks for the prompt replies. @Nimrod - You were right about the permissions on /home/john-scott/ workspace, chmod 755 fixed that. But I still have to have the django development code in /opt to get it to load. Any ideas why symlinking to /home/john-scott/workspace/django_src/django doesn't work? @Vincent - Is specifying the path necessary because I'm using the development version of django and not an official installer? In the official docs it says you only have to specify the path "if you've manually altered your PYTHONPATH to put your Django project on it". I didn't make any such adjustment. But it's also unclear to me how else a django project be on the PYTHONPATH. I understand that __init__.py tells python to load the files in that directory as a module, but python would need to know what directory to look for that file... And where do you typically keep the template and/or admin media files? Can these be kept in /home/john-scott/workspace/mysite/{templates| admin_media} etc.? Or do these have to be placed under /var/www? Thanks again --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ubuntu 6.06 deployment issues
On Jul 5, 11:33 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > You want to have the 'django_src' directory linked onto your Python > path, not the 'django' directory -- the Python path should contain the > *parent* directories of any modules you want Python to be able to > find. According to http://www.djangoproject.com/documentation/install/, these are the two commands for setting up the development version of django: svn co http://code.djangoproject.com/svn/django/trunk/ django_src ln -s `pwd`/django_src/django SITE-PACKAGES-DIR/django In my case, my `pwd` would be /home/john-scott/workspace, so this is where django_src is created and then the subdirectory `pwd`/django_src/ django would be symlinked to /usr/lib/python2.4/site-packages/django. Am I misunderstanding something? I'm getting sleepy, so anything is possible ;) > Media files to be served directly need to be in a location under the > web server's document root, but templates can be in any location > that's readable by the user the web server is running as, and it's > generally a good idea to have as few Django-related files in the > document root as possible. > > Remember that there are a number of different template loaders > available for Django which can look in different places automatically > -- the "app directories" one, for example, automatically looks inside > any installed application's directory for templates. I guess I was confused by the fact that the settings.py file contains these comments: # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" ...so I assumed it was 'ok' to store all static media files in a similar directory (i.e. '/home/john-scott/workspace/mysite/media'). At this point I realize I'm not at all clear on how the settings in settings.py (i.e. MEDIA_ROOT, MEDIA_URL, ADMIN_MEDIA_PREFIX) are supposed to interact with the Apache config. back to the docs... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ubuntu 6.06 deployment issues
On Jul 6, 12:29 am, Graham Dumpleton <[EMAIL PROTECTED]> wrote: > Hmmm, I'm not sure the documentation is actually accurate. When you > use manage.py to run up development server for Django, it will > automatically add the parent directory of where the manage.py file is > located into sys.path for you. Thus, there isn't strictly a need to > add it to PYTHONPATH to get it to work in the first place. > > So, the answer is that YES, for mod_python you must use the PythonPath > directive to specify the parent directory of where manage.py is > located in order for your settings file to be found correctly. > > Graham Graham - I was suspicious of that. I remember reading that manage.py took care of setting all the environment variables for the development server and interactive shell. But it didn't seem possible for mod_python to have any idea where our projects are implicitly. Should we file a doc bug? On Jul 6, 12:20 am, "Jeremy Dunck" <[EMAIL PROTECTED]> wrote: > MEDIA_ROOT is used for uploads (like FileField and ImageField. > MEDIA_URL should be the service URL matching MEDIA_ROOT; it is also > used in things like Model.get_FIELD_url where FIELD is the name of an > ImageField on your model. > > Probably, you want your doc root to be some prefix of MEDIA_ROOT (or > MEDIA_ROOT itself). > MEDIA_URL would be the portion of the MEDIA_ROOT not included in your > apache doc root (or '/' if the same). > > ADMIN_MEDIA_PREFIX is the URL portion under MEDIA_URL that is > symlinked to django/contrib/admin/media. (You don't need to worry > about this unless you're using the Admin app.) Jeremy - Thanks for the in-a-nutshell overview. I am in fact using the admin app, so that was my first hurdle to clear before getting fancy. I currently have the admin interface working. In my virtual host file I added: DocumentRoot "/var/www/mysite" SetHandler None SetHandler None In my settings.py, I now have: MEDIA_ROOT = '/var/www/mysite.com/media/' MEDIA_URL = 'http://mysite.com/media/' ADMIN_MEDIA_PREFIX = '/media/' Does this look about right? /var/www/mysite is empty other than the 'media' subdirectory. I suppose I could have apache alias requests to / media/ to whatever folder. I'll get fancy after some sleep ;). Once I get things settled, I'll try to contribute lessons learned to the wiki. Anyway, want to say thanks again to everyone for chiming in, this is one of the friendliest and most helpful user groups I've had the pleasure of participating in. I was born in a small midwestern city not far from Lawrence, KS, so I'm exited to get involved with a web framework of similar origins ;) 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
flatpages issues
hi gang, I'm trying out the flatpages app but not having a great deal of success. I've followed the instructions at http://www.djangoproject.com/documentation/flatpages/. I've added a directory in my templates folder (templates/flatpages/ default.html) according to the example in the documentation. I used the admin interface to make a dummy page 'about' with a URL value of '/ about/' and my site selected for the page. However, when I try to access the url (mysite.com/about/) I get an error saying that it tried using the url patterns in urls.py but "The current URL, about/, didn't match any of these." (I have DEBUG = True in settings.py). If I add: (r'', include('django.contrib.flatpages.urls')), to the urls.py, then I get an error saying "No FlatPage matches the given query." What am I doing wrong? From the official documentation it seems that I shouldn't have to add anything to urls.py, since that's the whole point: flatpages catches the 404 error for url patterns not found in urls.py then checks if there is a match in the database and render the result or else re-raises the 404. Thanks, j-s --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: flatpages issues
Can someone in the know confirm or deny that adding the catch-all line to urls.py is in fact required to invoke flatpages? I checked out the source for djangoproject.com and it has this as the last item in urlpatterns: (r'', include('django.contrib.flatpages.urls')), If this is required, should I file a ticket on the documentation to get this included in the instructions? Thanks. j-s --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Slug (w/o using SlugField) Problems
Hello, I'm using a solution I saw on a RoR blog (http:// blog.hasmanythrough.com/2006/7/7/more-on-naming-and-the-crud has a summary of the technique) which should address the 'reversibility' issue. Basically you just concatenate the object id with the slug of the human readable name, but then just ignore everything but the object id in your urlpatterns. First, you'd change your model like so: def get_absolute_url(self): return "/characters/%s/" % self.id + '-' + (slugify(self.name)) This will generate urls like "/characters/123-bob-and-jane". Next, change your urls.py like so: (r'^characters/(?P\d+)[-\w]+/$', object_detail, dict(character_detail_dict)), This should capture the '123' and discard '-bob-and-jane'. This is a fairly elegant solution that allows you to still have 'pretty' urls that are human readable and google friendly while completely sidestepping the complications of record retrieval based on reverse engineering slugs or bothering with a slug column, opting instead for the dead-simple and fast id lookup. Hope this helps. Btw, I assume you're just importing the slugify method from django.template.defaultfilters? This is what I did, rather than write my own method. Cheers, John-Scott (note: I tried writing this response a few hours ago, but it doesn't appear to have posted correctly. If it magically appears, I'll remove the duplicate post) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Slug (w/o using SlugField) Problems
The option I want to implement, and which my be a suitable solution for your situation, is to combine the object id with the slugified version of the object name. Then in your urls.py, only capture the object id and ignore the slug when retrieving the object (this gets you past any issues with reversibility). So you'd end up with something like: def get_absolute_url(self): return "/characters/%s/" % self.id + '-' + (slugify(self.name)) ...in your model, resulting in a url like "/characters/123-bob-and- jane". Your urls.py would need something like: (r'^characters/(?P\d+)[-\w]+/$', object_detail, ... This should capture the '123' of the slug and ignore the '-bob-and- jane'. So you only use the slug for pretty urls aka human readable and search engine friendly urls but still rely on the id value for quick and painless database lookups. My question is did you write your own 'slugify' method or is this included in core somewhere and I just need the appropriate import statement in my model files? Cheers, John-Scott On Jul 6, 4:27 pm, Tim Chase <[EMAIL PROTECTED]> wrote: > >> You might need to adopt a different approach to URL construction that is > >> reversible (writing your own version of slugify, possibly?). > > > Thanks for the help Malcolm. Using Jeff Croft's "I'm not a programmer" > > excuse, would it be too much trouble to request a small example of a > > reversible slugify? > > Given that any general "slugify" method throws away information > (case, spaces, punctuation, etc), there's no way to fabricate > that information for reversal short of keeping the original and > working backwards. > > However, you can use the urllib.quote() and urllib.unquote() > functions instead, which may do the trick. > > You may have to modify the regexp in your urls.py to handle > standard quoted characters rather than just "slug" chars. > > -tim --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Amazon S3 and S3FileField
Is anyone out there using S3FileField (http://code.djangoproject.com/ wiki/AmazonSimpleStorageService) in their models to interface with Amazon's S3 service? I've saved the code from the above url into a file 'amazon_s3.py' in my project directory (e.g. /amazon_s3.py) and I've saved the Amazon code from http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134&categoryID=47 into /amazon/. I've set the DEFAULT_BUCKET value in my settings file but I'm trying to figure out how to set the key for the S3FileField. There is a method called 'set_key' which apparently does this, but I don't know how to set this value in my model. My model currently looks something like this (and validates, so all the import statements seem to be in working order): from django.db import models from my_project.amazon_s3 import S3FileField class Photo(models.Model): photo_file = S3FileField() I would like to be able to set the key so that each file would be accessible from a url like http://s3.amazonaws.com//media/img/photo.jpg, that is, I want to set the key to "/media/img/" + file_name I have another question about the code from the wiki page. There is a keyword argument 'upload_to="s3"': class S3FileField(models.FileField): def __init__(self, verbose_name=None, name=None, bucket='', is_image=False, **kwargs): models.FileField.__init__(self, verbose_name, name, upload_to="s3", **kwargs) What does the value assigned to upload_to mean in the context of S3 storage? Any tips appreciated. Cheers, John-Scott --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Python 2.5 + MySQLdb
I'm not using windows these days, but taking a quick look at http://sourceforge.net/projects/mysql-python seems to indicate that they've only compiled a windows installer that depends on python2.4. You have at least two options, 1) download the source for mysql-python and attempt to build it yourself or 2) install python2.4. It might just be easiest to install python2.4 (unless 2.5 really has something you can't live without), you can have both versions installed side by side (c:\python2.4 & c:\python2.5). John-Scott On Jan 11, 3:41 am, Carl Holm <[EMAIL PROTECTED]> wrote: > Thanks, > > I'm getting the impression that MySQLdb is not available to Python 2.5, > but if anyone is using this configuration, I would like to > find out about the details. The OS in question is WinXP - Version 5.1.2600. > > Regards, > > CL > > Brett Parker wrote: > > On Wed, Jan 10, 2007 at 02:21:38AM -0800, Carl Holm wrote: > > >> Hello, > > >> After attempting to run Django with Python 2.5, I get the following > >> after trying to connect: to dev server: > > >> 'Error loading MySQLdb module: No module named _mysql' > > >> Any further info would be appreciated. > > > Looks like you're missing the C library behind MySQLdb, check that you > > have python2.5-mysqldb installed. > > > 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: flatpages issues
Yes sir. I followed the examples in the official docs literally and in order (http://www.djangoproject.com/documentation/flatpages/#installation steps 1-3). That worked fine and I was able to immediately start creating flatpages via the admin interface. But I cannot view flatpages on the site. I only added the line to urls.py because I saw some other example somewhere with the catch-all-else pattern but this did seem to at least get me one step closer. Without the urls.py addition, flatpages does not seem to be invoked to handle the 404 at all. Cheers, j-s On 7/13/07, Jacob Kaplan-Moss <[EMAIL PROTECTED]> wrote: > > > Hi John-Scott -- > > Did you add ' > django.contrib.flatpages.middleware.FlatpageFallbackMiddleware' > to your ``MIDDLEWARE_CLASSES`` setting? > > Jacob > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: flatpages issues
Ah ha! I just looked through my settings.py file and noticed the setting: SITE_ID = 1 I decided to double check the raw data for the django_sites table and my site id is '2'. (I think id 1 used to be 'example.com' but I had deleted it instead of renaming it, thus creating a mismatch with SITE_ID). Once I changed the SITE_ID value everything started working. I deleted the item from urlpatterns, and you're right, it's unnecessary. Thanks for attempting to get me sorted out. Cheers, John-Scott. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---