On Fri, Sep 25, 2009 at 9:05 AM, DavidA <david.avraami...@gmail.com> wrote:
> > I'm getting this error when I try to remove an inline model instance > in the Django admin: > > Traceback: > File "C:\Python25\lib\site-packages\django\core\handlers\base.py" > in get_response > 92. response = callback(request, *callback_args, > **callback_kwargs) > File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" > in root > 490. return self.model_page(request, *url.split > ('/', 2)) > File "C:\Python25\lib\site-packages\django\views\decorators > \cache.py" in _wrapped_view_func > 44. response = view_func(request, *args, **kwargs) > File "C:\Python25\lib\site-packages\django\contrib\admin\sites.py" > in model_page > 509. return admin_obj(request, rest_of_url) > File "C:\Python25\lib\site-packages\django\contrib\admin > \options.py" in __call__ > 1098. return self.change_view(request, unquote(url)) > File "C:\Python25\lib\site-packages\django\db\transaction.py" in > _commit_on_success > 240. res = func(*args, **kw) > File "C:\Python25\lib\site-packages\django\contrib\admin > \options.py" in change_view > 835. change_message = > self.construct_change_message(request, form, formsets) > File "C:\Python25\lib\site-packages\django\contrib\admin > \options.py" in construct_change_message > 535. 'object': > force_unicode(deleted_object)}) > File "C:\Python25\Lib\site-packages\django\utils\encoding.py" in > force_unicode > 71. s = unicode(s) > File "C:\private\src\itweb\..\itweb\controls\models.py" in > __unicode__ > 160. return self.document.url > You don't include this __unicode__ method in the code below, but this is likely where the problem is. What the admin is trying to log is the unicode value of your deleted object. I think you need to change your model's unicode method so that it does not trigger an exception when it is called for an instance that has no associated file. Karen > File "C:\Python25\lib\site-packages\django\db\models\fields > \files.py" in _get_url > 68. self._require_file() > File "C:\Python25\lib\site-packages\django\db\models\fields > \files.py" in _require_file > 46. raise ValueError("The '%s' attribute has no file > associated with it." % self.field.name) > > Exception Type: ValueError at /admin/controls/review/24/ > Exception Value: The 'document' attribute has no file associated > with it. > > I can see that the file is being deleted on disk, but then it looks > like this error is being thrown when the admin is trying to display a > summary message of what was done, and that triggers a _require_file() > call which raises an exception. > > I have the following models: > > class Review(models.Model): > name = models.CharField(max_length=80) > review_type = models.CharField(max_length=20, > choices=REVIEW_TYPE_CHOICES) > frequency = models.CharField(max_length=20, > choices=FREQUENCY_CHOICES, > null=True, blank=True) > description = models.TextField(null=True, blank=True) > > class Evidence(models.Model): > review = models.ForeignKey(Review) > review_time = models.DateTimeField(null=True, blank=True) > reviewed_by = models.ForeignKey(User, null=True, blank=True) > document = models.FileField(upload_to='evidence/%Y/%m/%d') > > And admin classes: > > class EvidenceInline(admin.TabularInline): > model = Evidence > > class ReviewAdmin(admin.ModelAdmin): > list_display = ['name', 'review_type', 'frequency', > 'description'] > list_filter = ['review_type', 'frequency'] > search_fields = ['name', 'description'] > fieldsets = [ > (None, {'fields':['name', 'review_type', > 'frequency']}), > ('Details', {'fields':['description']}), > ] > inlines = [EvidenceInline] > > admin.site.register(Review, ReviewAdmin) > > Am I doing something wrong? > > Thanks, > -Dave > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---