Commits

b7w committed fa77840

Fix validation for title

Comments (0)

Files changed (2)

bviewer/profile/admin.py

             obj.thumbnail = None
         super(ProfileGalleryAdmin, self).save_model(request, obj, form, change)
 
-    def add_view(self, request, form_url='', extra_context=None):
+    def get_form(self, request, obj=None, **kwargs):
         # Add default parent Welcome gallery
         user = ProxyUser.objects.get(pk=request.user.pk)
         data = request.GET.copy()
         data = request.POST.copy()
         data['user'] = user.id
         request.POST = data
-        return super(ProfileGalleryAdmin, self).add_view(request, form_url, extra_context)
+        return super(ProfileGalleryAdmin, self).get_form(request, obj=None, **kwargs)
 
     def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
         """

bviewer/profile/forms.py

     def clean_title(self):
         title = self.cleaned_data['title']
         user_id = self.data['user']
-        if Gallery.objects.filter(title=title, user_id=user_id).count() > 0:
+        if Gallery.objects.filter(title=title, user_id=user_id).exclude(id=self.instance.id).count() > 0:
             raise ValidationError('Title must be unique')
         return title