from django.db import models
from taggit.managers import TaggableManager
from django.contrib import admin

def resolve_upload_path(prefix):
    def _resolve(instance, filename):
        return '%s/%s/%s' % (instance.name, prefix, filename)

    return _resolve

def resolve_upload_path_image(instance, filename):
    return resolve_upload_path('images')

def resolve_upload_path_schematics(instance, filename):
    return resolve_upload_path('schematics')

def resolve_upload_path_layout(instance, filename):
    return resolve_upload_path('layout')

class OpenHardware(models.Model):
    '''
    This model represents the Open Hardware device linked with all the
    available informations.
    '''

    name = models.CharField(max_length=50)
    short_description = models.CharField(max_length=150)
    description = models.TextField()

    url        = models.URLField(help_text=u'Main site')
    image      = models.ImageField(upload_to=resolve_upload_path_image) # TODO: multiple images
    schematics = models.FileField(upload_to=resolve_upload_path_schematics)
    layout     = models.FileField(upload_to=resolve_upload_path_layout)

    tags = TaggableManager()

    def __unicode__(self):
        return self.name

@admin.register(OpenHardware)
class OpenHardwareAdmin(admin.ModelAdmin):
    list_display = [
        'name',
        'short_description',
    ]
@@ -99,16 +99,45 @@
 t admin%0A
+from config import settings%0A%0A
 %0Adef res
@@ -1246,16 +1246,354 @@
 f.name%0A%0A
+class OpenHardwareLike(models.Model):%0A    '''%0A    Connect the User to the Open Hardware she likes.%0A    '''%0A    user = models.ForeignKey(settings.common.AUTH_USER_MODEL)%0A    oh   = models.ForeignKey(OpenHardware)%0A%0A    @staticmethod%0A    def get_oh_for_user(user):%0A        return %5B_.oh for _ in OpenHardwareLike.objects.filter(user=user)%5D%0A%0A%0A
 @admin.r

Add OpenHardwareLike model.