Reputation: 3
I have following simplified setup:
What I want is to perform the "save" operation only on the inline-model. I thought as all fields are readonly it should work fine. Can someone give me a hint to do this in clean way?
class Legacy(models.Model):
legacyData = models.TextField()
def clean(self):
raise ValidationError("%s model is readonly." % self._meta.verbose_name.capitalize())
class Comment(models.Model):
legacy = models.OneToOneField(Legacy)
comment = models.TextField()
class LegacyAdmin(admin.ModelAdmin):
def __init__(self, *args, **kwargs):
self.readonly_fields = self.fields
super(LegacyAdmin, self).__init__(*args, **kwargs)
model = Legacy
inlines = (CommentInline, )
Thanks a lot for your time! :)
Upvotes: 0
Views: 1026
Reputation: 12968
Rather than raising an exception in clean(), you could override the legacy's save() and use http://docs.djangoproject.com/en/dev/ref/contrib/messages/ to tell your user what didn't happen.
Upvotes: 1