Entries : Category [ Django ]
The Django web development framework
[OpenBSD]  [BSD]  [FreeBSD]  [Linux]  [Security]  [Python]  [Zope]  [Daily]  [e-shell]  [Hacks]  [PostgreSQL]  [OSX]  [Nintendo DS]  [enlightenment]  [Apache]  [Nintendo Wii]  [Django]  [Music]  [Plone]  [Varnish]  [Lugo]  [Sendmail]  [europython]  [Cherokee]  [self]  [Nature]  [Hiking]  [uwsgi]  [nginx]  [cycling]  [Networking]  [DNS] 

24 enero
2008

Django People

yes, there I am...

Yesterday I found djangopeople, a website to track django users all over the world.

There, you can check if there are django users in your country and get some information about them too.

I've added myself to the list of spanish users, just to find that there is another guy here in lugo that plays with django, interesting!

This site is an interesting addon to the list of meaningful sites related to django:

Posted by wu at 12:42 | Comments (0) | Trackbacks (0)
08 mayo
2008

django hacks: accesing a model.field verbose_name...

...directly within a view.

My first django hack, imagine you have a model like:

class Project(models.Model):

    """ A sample django model """

    name = models.CharField('Project name', max_length=250)
    start_date = models.DateField('Project started on')
    employee = models.CharField('Project associated to', max_length=250)

    def __unicode__(self):
        return self.name

    class Admin:
        list_display = ('name', 'start_date', 'employee')
        list_filter = ['employee']
        search_fields = ['name']

    class Meta:
        ordering = ['-start_date']
        verbose_name_plural = 'Projects';

Once we have our model, we can play with it through a python shell. In order to do that, we have to use the shell command of manage.py:

snowball:SomeProject wu$ python manage.py shell

This way, all the neccesary deps from django will be pre-loaded and we will end in a python console running inside our project environment. Then, we can do something like:

Python 2.5.2 (r252:60911, Apr 29 2008, 23:50:14)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from SomeProject.iapm.models import Project
>>> p = Project.objects.all()[0]
>>> p
<Project: francisco_2008_03>
>>>

Here, I've imported the Project model, which is a class, then I created an instance of that class getting some data from the database (the first entry in the projects list) and using such data to populate the attributes of the model's class (name, start_date and employee).

Next, I called the instance itself, which will call the __unicode__ method, which will return a unicode object contaning the project name.

Of course, I could check the different attributes of the instance, like the name:

>>> p.name
u'francisco_2008_03'

or the employee:

>>> p.employee
u'Wu'

With that, I got the value for each attribute but, what if I would like to show something like:

Atribute: value

Each field object have two attributes, name and verbose_name, that will show the name of the field when called. The problem appeared when I tried to access those attributes directly:

>>> p.employee.name
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'unicode' object has no attribute 'name'
>>> p.employee.verbose_name
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'unicode' object has no attribute   'verbose_name'
>>>

What happened here? Well, it is pretty easy to understand. When I called p.responsable what I got in return is an unicode object, which doesn't have nor a name attribute, neither a verbose_name attribute.

Well, thnx to theju in the #django irc channel (irc.freenode.net) I found a workaround:

>>> p._meta.get_field('responsable').verbose_name
'Responsable de proyecto'

Here, I called the get_field method to get a field object, which does have a verbose_name attribute. Easy, isn't it?

So I finally got something like:

>>> print p._meta.get_field('employee').verbose_name + ': ' + p.employee
Project associated to: Wu

Of course that could be used inside a view to, for example, create a list of empty attributes from a given model.

Posted by wu at 16:54 | Comments (0) | Trackbacks (0)
01 agosto
2008

I'll be at the djangocon

yes, yes yeeeeees! I finally made it!

I've been waiting to post about it for a while now, but I think is time to talk a little bit about it.

The first django congress website

Three weeks ago, the first djangocon was announced. That announce made a lot of noise over the django community, but there wasn't too much information about it. We only knew that it will be at Googleplex on september (6th and 7th) and that only 200 people will have access to it.

Just 10 minutes after reading the announcement, I realized myself that I had to be there. Quickly I searched over the internet for flying tickets from Madrid to San Francisco and from Barcelona to San Francisco. Obviously I began to plan what would be a trip to the bay area, not only to assist to the djangocon but to be there more time.

From the 14th until the 22nd I keep myself searching, planning, checking... and on the 22nd I got the flying tickets (for me and my gf) from Barcelona to San Francisco (yes, I didn't know then if I'll have a place at the congress..). We will be in the bay area from september the 2nd to september the 14th.

Once I got the tickets, I began to check regularly both the django project website and the djangocon website itself, as in the announcement I had read that the tickets would be released in a few days. I've to admit that I couldn't wait to get one!.

And finally, yesterday at 12:00 UTC (14:00 GMT+2, the current time zone in spain) the first batch with 100 tickets was released. It wasn't my first time on this kind of situations, trying to log in a website to get tickets for some event, so I knew what would happen. And yes, it happened, just 10 minutes before the tickets release the djangocon website almost didn't answer to my browser requests. I began to feel myself excited, nervous. For a while it seemed like no response would came from the web... then, suddenly, a Proxy Error showed up on screen...

I've to admit I began to think that I could have lost my opportunity. But then, as suddenly as the proxy error message appeared some seconds before, the registration link did appear on screen! I filled every field on the form and I barely couldn't believe that I had made it, YES! I shout loudly in the office (luckily, my mates already knew I was trying to get a ticket).

And now I have the ticket, I have the flight reservations and I'm sure I'll be there!

Of course we have a lot of work to do before september. We will have to plan some trips/excursions over california, book some rooms on a (hope so) nice place to stay and such things but, hey, the hardest work is done!

P.S.: mmm don't know if someone from the bay area will read this, but.. any recommendation about the accomodation/hotel?

Posted by wu at 11:00 | Comments (0) | Trackbacks (0)
14 agosto
2008

upgrading django applications to recent revisions

yes, I should have written something by myself...

With the release of django 1.0 taking place in less than one month, there've been a lot of movement in django's svn repositories. Both alpha and alpha 2 versions were released last weeks and, as we could read in empty thoughts (the weblog from Michael Trier), there has been some new improvements/changes that will result in our webapps/websites crashing.

Of course, as everything else in django, the changes are well documented, and there is even a BackwardsIncompatibleChanges page in the project wiki, where you can get more information about the changes and how to solve the posible problems derivated from them.

I've suffered such incompatible changes myself during the first codigo23 sprint last week. Nothing really difficult to solve (mostly the move from admin to newforms-admin). Even some hours ago, I've found that our code have problems with the latest alpha 2 release (things related to the FileStorage refactoring).

If you are planning to upgrade your django-based webapps/websites to the latest revision, perhaps you will find useful a post from Ross Poulton in his blog. With "How I Moved My Commercial Projects to Newforms-Admin", Ross explains how he upgraded some well-known sites like djangosites.com in an easy way.

Posted by wu at 13:52 | Comments (0) | Trackbacks (0)
30 agosto
2008

Codigo23 & django t-shirts

or how to dress you up with style!

One week for the djangocon to take place and my TODO list almost empty (almost decided the car rental service and everything is prepared to be packed up tomorrow). On Monday I'll take a flight to Barcelona and on Tuesday a flight to San Francisco (with a short stop at Philadelphia).

But, before leaving, I would like to show you one thing. This is the design for a t-shirt we've made at Codigo23 for the djangocon:

Codigo23 and django in the same t-shirt!

I'll wear this t-shirt while being at the djangocon (yes, I know there will be t-shirts from the organization, but I ordered these ones a lot of time before they advice us) so I've ordered 3 of them for me and some more for whoever would like to get one.

That means, that you can get one if you like (even if you are not going to attend the djangocon). The cost of the t-shirt is 15 euro and for each t-shirt you buy, Codigo23 will donate 15 + 5 euro to the django project (that is, the price of the t-shirt + 5 euro extra).

We have M, L and XL sizes (european fit) and if you are interested, just contact me by mail or drop a comment to this post.

Posted by wu at 14:15 | Comments (0) | Trackbacks (0)
06 septiembre
2008

djangocon 2008: about to begin

yeah, and I'm here to enjoy it!

The first django congress website

Here I'm, after 3 memorable days in San Francisco (no time to post about it, sorry) I'm currently in Google, inside building 40-1, waiting for the djangocon to begin (5 minutes or so and the party will be start).

Posted by wu at 19:07 | Comments (0) | Trackbacks (0)

djangocon 2008: guido van rossum on app engine

yes, django -> appengine and appengine -> django is posible!

The first django congress website

Just finished some minutes ago the talk about google's app engine, he covered some highlights on the app engine itself, followed by some comments on the django roots of the engine and how to run django 1.0 apps on top of it.

It seems there are some issues with the free account and django 1.0, but people is working hard to create some scripts/tools to get that task as easy as posible.

Finally, guido show us a little posting-like demo tool built on top of the app engine, and I've to say it is pretty similar to build django-based applications.

Now, on to Brian Rosner - What's new in newforms admin

Posted by wu at 20:41 | Comments (0) | Trackbacks (0)

djangocon 2008: brian rosner on newforms-admin

the new way to manage things in the django admin interface

The first django congress website

A quick one this time, Brian covered the most important new features/changes in the django admin interface due to the merge of the newforms-admin branch into the trunk.

Things like the new formset concept, the admin.autodiscover() method or the new way to define edit_inline in your models.

One of the highlights of this talk, for me, is to know that now you can have multiple, independent, admin sites in the same project (nice!).

Now on to Jacob Kaplan Moss - State of Django (while having lunch).

UPDATE: during the questions round, a guy have explained how he use two different admin sites in a project, to give access to different kind of data to different users. That's pretty insteresting, as you can show different admin control panels for (for example) contributors, authors, editors, etc.

Posted by wu at 20:50 | Comments (0) | Trackbacks (0)

djangocon 2008: adrian holovaty and jacob kaplan-moss on state of django

a great overview of the project through time.

The first django congress website

While having lunch (chicken lasagna and salad), Adrian Holovaty gave us a talk about django from the beginning to the pre-1.0 state. An entertaining one.

Following Adrian, Jacob Kaplan-Moss gave us a talk about the state of django since 18 months before 1.0 (last monday). He covered some of the major features/works that had been made during this time.

Now on to Christian Hammond & David Trowbridge - Reviewboard

Posted by wu at 23:14 | Comments (0) | Trackbacks (0)
07 septiembre
2008

djangocon 2008: Malcolm Tredinnick on the django ORM

the plumber is here man!

The first django congress website

One of the most interestings talks up until now, Malcolm Tredinnick covered some aspects on how the ORM works, how to different data storage backends are defined (and how a new backend could be created) or how to understand django's QuerySet and Query objects.

I'm getting tired myself (as I didn't sleep so much last night), so I missed some parts of the talk while in a sleepy-halfstandby state :(

Now on to Justin Bronn - Geodjango (just after the snack break)

Posted by wu at 01:07 | Comments (0) | Trackbacks (0)
[1]   2   3   Next