views:

27

answers:

1

Hi guys, i have a "rare" behavior here, i this model:

models.py

class Area(models.Model):
    area = models.CharField(max_length=150,unique=True)
    slug = models.SlugField(max_length=200)
    fecha = models.DateTimeField(default=datetime.date.today,editable=False)
    activa = models.BooleanField(default=True)

class Empresa(models.Model):
    usuario = models.ForeignKey(User)
    nombre = models.CharField(max_length=150)       
    telefono = models.CharField(max_length=20)
    fax = models.CharField(max_length=20,null=True,blank=True)
    actividad = models.ManyToManyField(Area)

I dont know why the m2m_field actividad, into the django admin and any forms html is showing the slug field from the model Area as label

alt text

A: 

i was just returning the slug field and not the area "name"

class Area(models.Model):
    area = models.CharField(max_length=150,unique=True)
    slug = models.SlugField(max_length=200)
    fecha = models.DateTimeField(default=datetime.date.today,editable=False)
    activa = models.BooleanField(default=True)

    def __unicode__(self):
        return self.area  # was self.slug

    def get_absolute_url(self):
        return '/areas/%s' % self.slug 
Asinox