开发者

Django and absolute url with slug

开发者 https://www.devze.com 2023-02-12 01:15 出处:网络
my model is like: class Modeloxy(models.Model): ... ... slug = models.slug() clas开发者_运维技巧s mymodel(models.Model):

my model is like:

class Modeloxy(models.Model):
      ...
      ...
      slug = models.slug()


clas开发者_运维技巧s mymodel(models.Model):
      marca = ...
      ...
      modelo = models.ForeignKey(Modeloxy)


      def get_absolute_url(self):
          return '/%s/%s/%s' % (self.marca,self.modelo__slug,self.pk)

So, i can't get the absolute url usin self.modelo__slug.... how i will do that?

thanks guys


It would be self.modelo.slug

The double underscore syntax was created to solve the problem of not being able to use dot syntax as a keyword argument function(keyword_arg=Foo) and unrelated to python: you're literally looking for a variable named modelo__slug in your case.

0

精彩评论

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