How can I set a field in admin to be at the same time non-editable and prepopulated from other field ?
readonly works only for 1.2 on on my server I have 1.1 . I've tried 'editable=False' in my model field declaration, but together with prepopulate it raises an error.
markus glock
2010-07-12 04:27:20
A:
django-autoslug might be helpful.
ex:
from autoslug.fields import AutoSlugField
class FooModel(models.Model):
title = models.CharField(max_length=200)
pub_date = models.DateField(auto_now_add=True)
slug = AutoSlugField(populate_from='title', unique_with='pub_date__month')
Ashok
2010-07-12 05:38:23
+1
A:
From what I understand, prepopulate is there to prepopulate an editable field in the admin form. If you want to have one field's content automatically generated based on another's, then prepopulate is not what you want.
The way I usually do this is by setting the field to be non-editable, not prepopulating it, and overriding the model's save() method to get the value from the other field as necessary.
For automatic unique slug generation, Ashok's suggestion is the way to go.
Lexo
2010-07-12 06:20:43
I've found a better solution for generating slugs - http://trac.django-fr.org/browser/site/trunk/project/links/slughifi.py?rev=47
markus glock
2010-07-12 12:23:35
@markus That's a really cool extension to slugify. Thanks for letting me know about it!
Lexo
2010-07-16 21:25:31