Yet another class to simplify field choices creation. Keeps order, allows i18n.
Before:
ONLINE = 0
OFFLINE = 1
STATES = (
(ONLINE, _('online')),
(OFFLINE, _('offline'))
)
state = models.IntegerField(choices=STATES, default=OFFLINE)
After:
STATES = Choices(
('ONLINE', _('online')),
('OFFLINE', _('offline'))
)
state = models.IntegerField(choices=STATES, default=STATES.OFFLINE)
I'm using Django 0.96 for a project, and the url tag does not have all the capabilities I need.
I want a way to persist all or some of the GET parameters between requests. I also want a way to add to the current url a list of extra parameters, or nullify certain parameters.
In this snippet I am defining 2 tags ... link_persist and link_add.
It only works with Django 0.96, as the API changed ... but maybe a good soul can fix it for 1.0, as I haven't had any time available.
A tip for usage: if you specify a parameter as being the empty string, or None, the parameter will be removed from the link. When you specify a parameter already available in GET, it will replace it.
This is an override the save method of our Photo model. This new save method essentially takes the image, thumbnails it into our various sets of dimensions (for … in self.IMAGE_SIZES…), and save each one (into its own ImageField) before finally call the overwritten method to save the original image.
Yes, the dimensions are hardcoded, and there is currently not a way to regenerate them in different sizes, but one shouldn't be that hard to come up with, because you just could just load each photo object to regenerate, then save it again (or something along those lines).
mattpdx helped a lot with figuring out this code.