Forums

django admin

I´ve made an app with django. It is working fine here. But when I try to inspect some model from django admin, I get nothing. I can see the model names, but each model is shown as empty. What is wrong? Thanks!

Have you registered models with admin.py?

I'm a django noob btw - no expert. :)

is your code hosted on github? If so give me the link and I'll clone it and play about with it. It helps me learn.

What do you mean by "empty"? Is there no record there? Is the record there, but the fields are not filled in?

Hi guys! Yes, the models were registered with admin.py. I can even download the tables updated with the app. I just can´t manage them from django admin... By "empty" I mean I can see the models (ex., "mymodel"), but it says like "0 mymodel models" (no need to say I´m django noob too...). The code, Dseymor71: https://github.com/mauricioamm/Eprog2_1.git. Thank you!

If you're using sqlite, then it's because you have not put the database file on PythonAnywhere. In general, tutorials will exclude the sqlite database from the git repository so that you do not overwrite the live database with a development one. If you want to use the database that you have on your machine as a starting point, you will need to upload it to PythonAnywhere.

Yes, sqlite. I was not aware of that, thanks! Interestingly, I can do all the CRUD stuff with the tables from my app (any machine, not just local). When I download tables with my app, everything is Ok. I just wanted to be able to do the same from django admin... A noob question: after deploying, I should be able to manage django admin just like before, right?

Just to be clear -- are you saying that your site's code can see the contents of the database (say, if it's a blog, all of the blog posts are being displayed) but you can't see the contents in the admin view?

Exactly, Giles

The thing I'm noticing about your code, you have lots of different sqlite dbs.

DATABASES = { 'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),}, 'mauricioamm': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'mauricioamm.sqlite3'), }, 'ellen': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'ellen.sqlite3'), }, 'lohana': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'lohana.sqlite3'), }, 'gabriela': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'gabriela.sqlite3'), }, 'john': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'john.sqlite3'), }, 'paul': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'paul.sqlite3'), }, 'george': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'george.sqlite3'), }, 'ringo': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'ringo.sqlite3'), }, 'p1': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'p1.sqlite3'), }, 'p2': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'p2.sqlite3'), }, 'p3': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'p3.sqlite3'), }, 'p4': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'p4.sqlite3'), }, 'p5': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'p5.sqlite3'), }, #no admin, dar como sobrenome aos cadastrados: p1, p2, p3, p4... }

when I looked at django admin there was no records in the models for the default?

could it be you need to synchronise all your dbs? https://docs.djangoproject.com/en/3.0/topics/db/multi-db/

That´s a good guess. Anyway, I think I should deploy it again

Normally I'd expect a Django app to have only one database; is there a particular reason why you have so many?