Django 和带 slug 的绝对 url
我的模型是这样的:
class Modeloxy(models.Model):
...
...
slug = models.slug()
class mymodel(models.Model):
marca = ...
...
modelo = models.ForeignKey(Modeloxy)
def get_absolute_url(self):
return '/%s/%s/%s' % (self.marca,self.modelo__slug,self.pk)
所以,我无法使用 self.modelo__slug 获得绝对网址...我将如何做到这一点?
谢谢大家
my model is like:
class Modeloxy(models.Model):
...
...
slug = models.slug()
class 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它将是
self.modelo.slug
双下划线语法的创建是为了解决无法使用点语法作为关键字参数的问题
function(keyword_arg=Foo)
并且与 python 无关:您实际上是在寻找一个名为modelo__slug
的变量。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 namedmodelo__slug
in your case.