4đź‘Ť
modocache,
What version of django are you using? What you have there listed should work, I use that same logic in many of my own models, and it works fine.
According to this page: http://fosshelp.blogspot.com/2010/12/django-override-save-method-two-ways.html
you should be able to change the code to look like this (below), and it will do the same thing but won’t reference the Post model.
def save(self, *args, **kwargs):
if not self.id:
self.slug = slugify( self.title )
models.Model.save(self, *args, **kwargs ) # <-- notice the self
Another point , instead of using “if not self.id:” it is generally better practice to use “if not self.pk:” instead. see these related links.
http://docs.djangoproject.com/en/dev/ref/models/instances/#the-pk-property
How that helps.
1đź‘Ť
I’m wondering if you have an indentation error at your super()
line — do you have tabs and spaces mixed up?
Upon starting the server even typing in super(IDONTEXIST, self)
should not throw an error until save()
is called.
I can reproduce your error if I de-indent the super line.
- [Django]-Asterisk in django forms validation messages
- [Django]-Using Python 3.7 on Pycharm gives me: "Error: Django is not importable in this environment"
- [Django]-Django compare query with F objects adds extra not null check