I'm using the Django Feeds Framework and it's really nice, very intuitive and easy to use. But, I think there is a problem when creating links to feeds in HTML.
For example:
<link rel="alternate" type="application/rss+xml" title="{{ feed_title }}" href="{{ url_of_feed }}" />
Link's `HREF` attribute can be easily found out, just use `reverse()`
But, what about the `TITLE` attribute? Where the template engine should look for this? Even more, what if the feed is build up dinamically and the title depends on parameters (like [this](http://docs.djangoproject.com/en/dev/ref/contrib/syndication/#a-complex-example))?
This is the solution I came up with. However, as you can see, there is some caveats:
* Requires Django 1.2 Class Feeds, don't know exactly how to do this with the old way of feeds.
* If the feed class uses the request object, the `request` [context processor](http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-request) must be configured, since `None` is passed if it isn't present in the context.
* There's an oddity with Feed.__get_dynamic_attr(). The Feed subclass instance doesn't have this method; instead, it appears with another name. Don't know how to figure the name out at runtime...
I've posted this problem on [StackOverflow](http://stackoverflow.com/questions/2784659/django-dry-feeds), but didn't get a better answer.
- Feeds DRY templatetag HTML LINK
This snippet for django-1.2 allows you to use bitwise operators without using QuerySet.extra()
from django.db.models import *
from somewhere import FQ
class BitWise(Model):
type = CharField(max_length=8)
value = IntegerField()
def __unicode__(self):
return '%s - %d' % (self.type, self.value)
>>> BitWise.objects.create(type='django', value=1)
<BitWise: django - 1>
>>> BitWise.objects.create(type='osso', value=3)
<BitWise: osso - 3>
>>> BitWise.objects.create(type='osso', value=7)
<BitWise: osso - 7>
>>> BitWise.objects.filter(FQ(F('value') & 1, 'gt', 0))
[<BitWise: django - 1>, <BitWise: osso - 3>, <BitWise: osso - 7>]
>>> BitWise.objects.filter(FQ(F('value') & 2, 'gt', 0))
[<BitWise: osso - 3>, <BitWise: osso - 7>]
>>> BitWise.objects.filter(FQ(F('value') & 1, 'gt', 0) & Q(type='django'))
[<BitWise: django - 1>]
- filter
- queryset
- bitwise
- operator
django-adminwidgetswap
===============
adminwidgetswap is used for dynamically swapping out widgets from django's generated admin.
This allows applications to be packaged generically without the need for WYSIWYG dependencies editors- giving the application consumer the freedom to chose admin widgets without modifying original app source.
Author
======
[David Davis](http://www.davisd.com)
(http://www.davisd.com)
[dynamically change django admin widets at runtime (django-adminwidgetswap) blog post](http://www.davisd.com/blog/2010/04/17/dynamically-change-django-admin-widgets-at-runtime/)
Usage
===============
To change a widget in django's admin, just put adminwidgetswap.py on the python path, import adminwidgetswap.py and use:
adminwidgetswap.swap_model_field(model, field, widget)
...to change a widget for a direct model admin's field
---
adminwidgetswap.swap_model_inline_field(model, field, widget)
...to change widgets for inlines of a specific model and field
---
adminwidgetswap.swap_model_and_inline_fields(model, field, widget)
...to change both the widget for the direct model admin's field as well as all inline usages for the model and field
---
I usually have a project-level application called website, and I put this initialization code inside the website app's __init__.py
Usage - parameters
===============
model is the Model class
(eg. models.GalleryImage)
field is the field name you're looking to swap
(eg. 'image')
widget is the widget you're going to swap for
(eg. widgetlibrary.ThumbnailWidget())
- admin
- widgets
- abstraction