I have a UserProfile related to auth's User model with a couple of extra date fields, start_date and end_date. I would like one and only one UserProfile that is editable inline with the parent User model in my Admin app. This part is working, but I would also like to do custom validation on the date fields in UserProfile so that start_date < end_date and also make sure that the lone UserProfile does not have a delete checkbox in the Admin. Here is a bit of the code:
models.py: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) start_date = models.DateField() end_date = models.DateField() admin.py: class UserProfileInlineFormSet(BaseInlineFormSet): def __init__(self, *args, **kwargs): super(UserProfileInlineFormSet, self).__init__(self, *args, **kwargs) self.can_delete = False # Validate end_date > start_date def clean(self): # ? pass class UserProfileInline(admin.TabularInline): model = UserProfile fk_name = 'user' max_num = 1 formset = UserProfileInlineFormSet class MyUserAdmin(admin.UserAdmin): inlines = [UserProfileInline, ] The docs explain how to do custom validation on a single ModelForm, but I'm having trouble abstracting that to an inline formset. I started with trying to define my own formset in the UserProfileInline class, but I'm not clear on what method to override in order to do the validation. Any tips or pointers? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---