This code provides a Django model for photos based on Flickr, as well as a script to perform a one-way sync between Flickr and a Django installation.
*Please note that the snipped contains code for two files, update.py and a Django model.*
*The two chunks are separated by:*
"""
END OF FLICKRUPDATE
"""
"""
START DJANGO PHOTO MODEL
Requires django-tagging (http://code.google.com/p/django-tagging/)
"""
My model implements tagging in the form of the wonderful django-tagging app by Jonathan Buchanan, so be sure to install it before trying to use my model.
The flickrupdate.py code uses a modified version of flickerlib.py (http://code.google.com/p/flickrlib/). Flickr returns invalid XML occasionally, which Python won't stand for. I got around this by wrapping the return XML in `<flickr_root>` tags.
To modify flickrlib to work with my code, simply change the this line:
return self.parseData(getattr(self._serverProxy, '.'.join(n))(kwargs))
to:
return self.parseData('<flickr_root>' + getattr(self._serverProxy, '.'.join(n))(kwargs) + '</flickr_root>')
I hate this workaround, but I can't control what Flickr returns.
flickrupdate will hadle the addition and deletion of photos, sets and tags. It will also keep track of photos' pools, although, right now, it doesn't delete unused pools. This is mostly because I don't care about unused pools hanging around. It's a simple enough addition, so I'll probably add it when I have a need.
Be sure to set the appropriate information on these lines:
api_key = "YOUR API KEY"
api_secret = "YOUR FLICKR SECRET"
flickr_uid = 'YOUR FLICKR USER ID'
I hadn't seen a Django model and syncing script, so I threw these together. I hope they will be useful to those wanting start syncing their photos.
- flickr
- photos
- photo
- flicker
This is the approach I've taken to access instances of child models from their parent. Functionally it's very similar to snippets [1031](http://www.djangosnippets.org/snippets/1031/) and [1034](http://www.djangosnippets.org/snippets/1034/), but without the use of `django.contrib.contenttypes`.
Usage:
class Post(ParentModel):
title = models.CharField(max_length=50)
objects = models.Manager()
children = ChildManager()
def __unicode__(self):
return self.title
def get_parent_model(self):
return Post
class Article(Post):
text = models.TextField()
class Photo(Post):
image = models.ImageField(upload_to='photos/')
class Link(Post):
url = models.URLField()
In this case, the `Post.children` manager will return a queryset containing instances of the appropriate child model, rather than instances of `Post`.
>>> Post.objects.all()
[<Post: Django>, <Post: Make a Tumblelog>, <Post: Self Portrait>]
>>> Post.children.all()
[<Link: Django>, <Article: Make a Tumblelog>, <Photo: Self Portrait>]
- model
- manager
- queryset
- inheritance
I'm working on a Project where on certain places I need absolute URL's, in development mode I need the port 8000 added to any absolute url.
This piece of work, took me some time to figure out. Couldn't find something similiar on the net, it's based on Code from the Python urlparse module.
You can change the "settings.PORT" part to "settings.DEBUG == True" if you like, and so on.
META: replace parameters in URL, edit parameters in URL, edit URL, urlparse
- url
- urlparse
- port
- replace-parameters-in-url
- urlsplit