Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin: missing inlines for some records

I'm having some problems here with django admin site and inlines. I've been googling for solution for two days now but nothing.

I have two models:

class Measurement(models.Model):
  user = models.ForeignKey(User)
  date = models.DateTimeField(auto_now_add=True)
  # etc

class Media(models.Model):
  measurement = models.ForeignKey(Measurement)
  link = models.CharField(max_length=255, blank=True)
  description = models.TextField(blank=True)
  # etc

And configuration for admin site:

class MediaInline(admin.StackedInline):
  model = Media
  extra = 0

class MeasurementAdmin(admin.ModelAdmin):
  inlines = [MediaInline,]

admin.site.register(Media)
admin.site.register(Measurement, MeasurementAdmin)

The strange thing is: admin site shows inlines for some Measurement objects and doesn't for some others. Whole formset is invisible (it's not there) even if related records are visible in database. Also, ValidationError: [u'ManagementForm data is missing or has been tampered with'] exception is raised for these objects. Have anyone dealed with this?

like image 283
Anpher Avatar asked Nov 04 '10 23:11

Anpher


1 Answers

In 90% cases i've seen this was due to error in __unicode__ method, which django use on inline template.

like image 54
Dmitry Shevchenko Avatar answered Sep 30 '22 18:09

Dmitry Shevchenko