开发者

django ManyToManyField show slug as label

开发者 https://www.devze.com 2023-01-16 05:36 出处:网络
i have a "rare" behavior here, i this model: models.py class Area(models.Model): area = models.CharField(max_length=150,unique=True)

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

django ManyToManyField show slug as label


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 
0

精彩评论

暂无评论...
验证码 换一张
取 消