Model overriding predefined model methods.

18 views
Skip to first unread message

Petey

unread,
Oct 8, 2011, 6:39:29 AM10/8/11
to django...@googlegroups.com
I'am writing a thumbnail generator for my Images model

Everything is working fine apart from saving path to the database.
http://wklej.to/AimKm

Could you give me some hints on model overriding?

Adrian Merrall

unread,
Oct 8, 2011, 6:53:20 AM10/8/11
to django...@googlegroups.com
Petey,

Could you give me some hints on model overriding?


Do you mean you want to override the default save method to put in some processing first?  This is covered here

https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods

If you are wanting to generate a legal URL slug, you can use the slugify method like this...

from django.template.defaultfilters import slugify

Class MyImageModel(models.Model):



    def save(self, *args, **kwargs):
            self.slug_field = slugify(self.some_unique_image_reference_field)

and then call the super save method as defined in the URL above.

HTH

Adrian
Auckland, NZ

 
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/XcPk-oFwFBQJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Petey

unread,
Oct 8, 2011, 9:08:30 AM10/8/11
to django...@googlegroups.com
Actually my code worked. Other code created some errors :)
Reply all
Reply to author
Forward
0 new messages