1

I have 5 models in one of my apps

Report ReportData Customer ..etc

For some reason, ever since my last deployment, I can no longer change or create new Report or Customer objects, but everything else works? Any idea why this would be happening? The admin page just outputs nothing on the add link and the change link outputs nothing as well.

Django==1.9.1

I have tried restarting servers, running migrations, and restarting database. The development version works fine. Such a strange problem.

enter image description here

As you can see, there are no fields even though this object has been populated with tons of data in the database.

Here is my Report model:

class Report(models.Model):
    public_uuid = models.UUIDField(max_length=256,default=util.make_uuid,unique=True)
    customer = models.ForeignKey('Customer')
    has_payed = models.BooleanField(default=False)
    #... etc

Here is how I register items in the admin:

admin.site.register(Customer)
admin.site.register(Report)
admin.site.register(...etc)

The other 3 models I have work fine. The only difference between these two models and the other three (that work and are editable with the admin tool) is that these two models have @property and @staticmethod methods attached to them.

Greg Schmit
  • 4,275
  • 2
  • 21
  • 36
dmcmulle
  • 339
  • 3
  • 11
  • what happens if you try to delete them ? – levi Aug 09 '16 at 23:46
  • @levi It deletes items fine – dmcmulle Aug 09 '16 at 23:48
  • how do you import your models into the `admin.py` file? – an0o0nym Aug 10 '16 at 02:16
  • It looks as if something is causing the changelist view to fail, and the Django admin is silently swallowing the error. You haven't shown enough information to reproduce the error. You could try running `print(list(Report.objects.all()))` in the shell, to see whether that triggers the same error, but with a traceback. – Alasdair Aug 10 '16 at 08:34
  • @Alasdair all of the items are printing fine. What else can I do to debug? – dmcmulle Aug 10 '16 at 18:33
  • I don't have any other suggestions. I don't think you've shown enough information to reproduce the problem, so I can't really help. Hope you figure out the problem. – Alasdair Aug 10 '16 at 18:44
  • @Alasdair Ended up being because one of my new customers put unicode in their name, and django admin couldn't output that. weird. Do you know how I can restrict Django model fields to only accept ascii? – dmcmulle Aug 10 '16 at 21:16
  • The Django admin can display unicode fine, there's probably a method on your model or model admin that's causing the problem. It would be better to fix that than restrict the model fields. – Alasdair Aug 10 '16 at 21:37
  • @dmcmulle there are really many similar questions like yours. You just need to search. For example [here](http://stackoverflow.com/questions/2984987/model-not-showing-up-in-django-admin), [here](http://stackoverflow.com/questions/1694259/django-app-not-showing-up-in-admin-interface), [here](http://stackoverflow.com/questions/24813536/django-admin-not-showing-models), [here](http://stackoverflow.com/questions/1839927/registered-models-do-not-show-up-in-admin) – an0o0nym Aug 10 '16 at 22:32
  • @an0o0nym None of those questions are similar to mine though. They specifically state that they aren't showing up, where mine show up but are not editable. And your first two links are 6 and 7 years old. – dmcmulle Aug 11 '16 at 01:17

1 Answers1

2

Just had this issue

When using auto_now_add=True or editable=False in the field definition, the admin will not show the corresponding fields unless you specify them in the readonly_fields of the admin form definition.

if in models.py

class TransmissionLog(models.Model):
     dataSource = models.ForeignKey(Browser, editable=False)
     dateCreated = models.DateTimeField(auto_now_add=True, editable=False)

then admin.py needs

class TransmissionAdminManager(admin.ModelAdmin):
    readonly_fields = ['dataSource', 'dateCreated']
admin.site.register(TransmissionLog, TransmissionAdminManager)
user3802077
  • 849
  • 9
  • 22