RkBlog

Diamanda back in SVN

Diamanda code is back in SVN, but it's still far from being done so expect a lot of changes. Currently the code was cleaned up a bit, I've removed my site specific code and made it work on latest Django-SVN (required).

svn checkout http://diamanda.googlecode.com/svn/trunk/ diamanda

› Read more

Upgrading Diamanda to Django-SVN

In the last few days I have been updating code of my sites to be more Django-SVN compatible, and to clean few things. Things that have been done:

  • Removed auto_now and auto_now_add as they will be gone (read here about it).
  • Renamed maxlength to max_length in models and oldforms forms
  • migrating from oldforms to newforms – boxcomments for now only :) newforms are much "bigger" than oldforms and "how to make this in newforms" takes some time.
  • Added |safe in templates where it's needed to show HTML
  • Some time ago – make it work after UTF branch merged :)
Plus code clean-up :) a lot of cleaning with imports, comments, and removed some unneeded "features". When all work will be done (newforms in Forum-Myghtyboard and other components) a new Diamanda release will go public.

› Read more

Google GData Authentication decorator

Google GData API can be used to retreive data from Google services... It can also be implemented on other sites (which I have on my ToDo list at my current job) helping in creation of backed applications. "Read" to see a simple view with custom decorator that authenticate user agains a GData provider (Google in this case). You can also read the auth docs.

› Read more

Django-SVN site upgrade

I've upgraded my sites to be Django-SVN compatible, and to fix/add some components. Comments can now be added by anonymous. As for 0.96 -> SVN code upgrade I had to solve a lot of unicode errors (as I use non ASCII Polish language). Sad thing is that I didn't noticed any new features that I can use. I have pyif template tag waiting as Django if tag can't compare < > so I'm unable to check if there are new posts in forums for current user. Yes, Django templates ARE limited, and Django developers should make them more flexible, even if they don't like logic in templates ( “ifequal” is good but if “a < b” is not?). There is a lot of Django components out there, and some of them should go into core django as add-on modules etc...

› Read more

Custom models fields?

I was wondering how to make a ForeignKey on a model and limit the choices in some way (for example allow adding subcategories only to root categories). So why not make a new class, that inherits models.ForeignKey and overwrite method that return the choices? My test code that works (it probably can be done a bit better...):

class FK(models.ForeignKey):
	def __init__(self, to, to_field=None, **kwargs):
		models.ForeignKey.__init__(self, to, to_field=None, **kwargs)
	def get_choices(self, include_blank=True):
		c = Category.objects.filter(id__gt=2)
		returnList = []
		for cc in c:
			returnList.append([cc.id, cc.cat_name])
		return returnList
	

class Category(models.Model):
	cat_name = models.CharField(maxlength=255, verbose_name=_("Category Name"))
	cat_order = models.PositiveSmallIntegerField(default=0, verbose_name=_("Order"))
	cat_foo = FK('self', verbose_name=_("test"), blank=True, null=True)
We override get_choices, and we are done. Other custom fields (not relations) should be even easier to create. Just look at django/db/models/fields/.

› Read more

RkBlog main page Search RSS Contact