I have a model with a custom field:

class Project(models.Model):
    slug = fields.AutoSlugField(max_length=50, unique=True,
editable=False, prepopulate_from="name", force_update=False)
    name = models.CharField(unique=True, verbose_name=_('Name'),
max_length=50, help_text=_('The project name to show to the users'))


class AutoSlugField(fields.SlugField):
    def __init__(self, prepopulate_from, force_update = False, *args,
**kwargs):
        self.prepopulate_from = prepopulate_from
        self.force_update = force_update
        super(AutoSlugField, self).__init__(*args, **kwargs)

    def pre_save(self, model_instance, add):
        if self.prepopulate_from:
            return slugify(model_instance, self, getattr(model_instance,
self.prepopulate_from), self.force_update)
        else:
            return super(AutoSlugField, self).pre_save(model_instance, add)


and a bounded form:

class ProjectForm(forms.ModelForm):
    class Meta:
        model = Project

when I call form.save() it returns a Project instance without the slug
value, although the field is correctly saved into the database.

Any idea why this is happening ?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to